Announcement

Collapse
No announcement yet.

HTTP Request failing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HTTP Request failing

    HI. I was following the following post: https://answers.unrealengine.com/que...p-request.html

    IHttpRequest::ProcessRequest() is returning false. This signifies that the request is not being processed. Here is the chunk of code I am using:

    FSagRequest CurrentRequest;
    CurrentRequest.AddURLPair(param, value);
    FString Dest;
    Dest.Equals("insertGameStats.php");
    CurrentRequest.SetDestination(Dest);


    TSharedRef< IHttpRequest > Request = FHttpModule::Get().CreateRequest();
    Request->SetVerb("POST");
    Request->SetURL(TargetHost + CurrentRequest.TheDest); //target="localhost"
    Request->SetContentAsString(CurrentRequest.TheData);

    Request->SetHeader("User-Agent", "XYZClient/1.0");
    Request->SetHeader("Content-Type", "application/x-www-form-urlencoded");

    Request->OnProcessRequestComplete().BindUObject(this, &AHTTPHandlerActor::OnResponseReceived);
    if (!Request->ProcessRequest())
    {
    //ASagittarius::LogError("Unable to process HTTP Request!");
    FString TestStringToBreak;
    TestStringToBreak.Equals("dfsf");
    }

    The code breaks at the last line, which means that the request failed. This in turn calls void AHTTPHandlerActor::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) , with Response==null

    Any help would be greatly appreciated.

    #2
    I think the order of the writing instructions was wrong. This is what solved it:


    TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
    Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
    Request->SetURL(TEXT("http://127.0.0.1/insertGameStats.php"));
    Request->SetVerb(TEXT("POST"));
    Request->SetContentAsString(CurrentRequest.TheData);

    Request->OnProcessRequestComplete().BindUObject(this, &AHTTPHandlerActor::OnResponseReceived);


    But, I am receiving null value at my php side. Here is how I set data:

    CurrentRequest.AddURLPair(param, value);
    void AddURLPair(FString param, FString value)
    {
    TheData += (delim + param + "=" + value);
    delim = "&";
    }

    Any help would be greatly appreciated

    Comment

    Working...
    X