赞
踩
纯接口调用,直接上代码
Build.cs中添加HTTP模块
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" , "HTTP"});
.h
void DownLoad(FString URL);
//下载完成调用
void HandleDownloadRequest(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded);
//处理下载进度
void HandleHttpRequestProgress(FHttpRequestPtr HttpRequest, int32 BytesSent, int32 BytesReceived);
.cpp
void UTestInstance::DownLoad(FString URL) { TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest(); HttpRequest->OnProcessRequestComplete().BindUObject(this, &UTestInstance::HandleDownloadRequest); HttpRequest->OnRequestProgress().BindUObject(this, &UTestInstance::HandleHttpRequestProgress); HttpRequest->SetURL(URL); HttpRequest->SetVerb(TEXT("GET")); HttpRequest->ProcessRequest(); } void UTestInstance::HandleDownloadRequest(FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse, bool bSucceeded) { if (!HttpRequest.IsValid() || !HttpResponse.IsValid()) { return; } else if (bSucceeded && EHttpResponseCodes::IsOk(HttpResponse->GetResponseCode())) { //保存文件 FString Filename = FPaths::GetCleanFilename(HttpRequest->GetURL()); FString Left; FString Right; Filename.Split("?", &Left, &Right); FFileHelper::SaveArrayToFile(HttpResponse->GetContent(), *FString::Printf(TEXT("%s%s"), *FPaths::ProjectContentDir(), *Left)); } } void UTestInstance::HandleHttpRequestProgress(FHttpRequestPtr HttpRequest, int32 BytesSent, int32 BytesReceived) { //Your code }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。