zoukankan      html  css  js  c++  java
  • ue4访问php接口

     继上一篇介绍ue4打开web url窗口,这篇就来介绍下怎么访问php接口。

    要做的两步:

    1.c++自己写个接受请求的方法

     f Post lhc-URL Request就是自定义的c++方法,

    /**###lhc 
    * 增加一个参数,接收一个FString,该参数的意义是:用URL的途径向php webservice发送数据,该数据的格式是key=value&key=value....
    *
    * @param	WorldContextObject		
    * @param	url						
    *
    */
    void UJsonFieldData::PostRequest_lhc(UObject* WorldContextObject, const FString pm_lhcDataconst, const FString& url)
    {
    	/*FString outStr;
    	TSharedRef<TJsonWriter<TCHAR>> JsonWriter = TJsonWriterFactory<TCHAR>::Create(&outStr);
    
    	// Start writing the response
    	WriteObject(JsonWriter, "", new FJsonValueObject(lhc_jsonData));
    	JsonWriter->Close();
    
    	// Log the post data for the user (OPTIONAL)
    	UE_LOG(LogTemp, Warning, TEXT("Post data: %s"), *outStr);*/
    
    	// Create the post request with the generated data
    	TSharedRef< IHttpRequest > HttpRequest = FHttpModule::Get().CreateRequest();
    	HttpRequest->SetVerb("POST");
    	HttpRequest->SetURL(CreateURL(url));
    
    	//###lhc 因为目前不知道php webservice取得JSON数据的代码怎么写,而且目前php service也没有必须获得客户端JSON数据(一个对象结构)的需求,
    	//因此,暂时先通过URL的方式发送数据,用Key=value的形式,每组Key=Value之间用&分隔,如:name=a1&password=q1
    	//HttpRequest->SetHeader("Content-Type", "application/json");
    	HttpRequest->SetHeader("Content-Type", "application/x-www-form-urlencoded");
    	
    	//###lhctmp
    	//HttpRequest->SetContentAsString(outStr);
    	//FString siwe = "name=a1&password=q1";
    	HttpRequest->SetContentAsString(pm_lhcDataconst);
    
    	HttpRequest->OnProcessRequestComplete().BindUObject(this, &UJsonFieldData::OnReady);
    
    	// Execute the request
    	HttpRequest->ProcessRequest();
    }
    

      

    2.按钮event

  • 相关阅读:
    作业
    作业
    [转]C语言指针 之 函数指针
    iOS 隐私政策
    微信小程序成长记录(一)
    ios 用信号量控制多个异步网络请求
    ios 利用cocapods创建私有库
    ios 整理获取设备相关信息
    ios_scrollView顶部图片下拉放大
    ios 在项目中使用文字ttf文件
  • 原文地址:https://www.cnblogs.com/y114113/p/6289834.html
Copyright © 2011-2022 走看看