UE5 c++ 实现网络http请求

¥ 19.90
2198
课程介绍

本课讲c++封装的http请求与json获取数据插件

c++ 核心请求代码

//开始请求
void UMetaAsyncHttpObject::HttpRequest(const FString& url, const FString& type, const FString& data,const FString& token)
{
    FString Host = Config::MetaHost+url; 
	TSharedRef<IHttpRequest, ESPMode::ThreadSafe> request = FHttpModule::Get().CreateRequest();
	request->SetVerb(type);
	request->SetURL(Host);
	request->SetHeader(TEXT("Content-Type"), TEXT("application/json;charset=utf-8"));
    request->SetHeader("Accept", TEXT("application/json")); 
    request->SetHeader("appid", Config::MetaAppId); 
	if (!token.Equals("")) {
		request->SetHeader("token", token);
	}
	request->SetTimeout(5000);
	if(!type.Equals("GET")){
		request->SetContentAsString(data); 
	} 
	//request->OnRequestProgress().BindUObject();
	request->OnProcessRequestComplete().BindUObject(this, &UMetaAsyncHttpObject::HttpRequest_RecHandle); //请求回调
	request->ProcessRequest();
}