Download

IHttpRequest::OnProcessRequestComplete not succeed on local machine

Hello. I’m running a server on my local machine and I’m sending a request via HttpRequest::ProcessRequest(). It works - I can see incoming data on my server. But EventRequestComplete delegate fires with bSucceeded == false. I tried to send a request to some random url (google.com), delegate fires with bSucceeded == true. Why? How can I test it on local machine?

Could you provide your code?
I have a local Server and Database myself and it works fine.

Hi! Sure:


FHttpRequestPtr HttpRequest = FHttpModule::Get().CreateRequest();
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
HttpRequest->SetURL(FString::Printf(TEXT("%s/?Event=%s"), *LocalhostUrl, *SomeString));
HttpRequest->SetVerb(TEXT("POST"));
HttpRequest->OnProcessRequestComplete().BindRaw(this, &FMyClass::EventRequestComplete);
HttpRequest->ProcessRequest();

Nothing unusual. With remote server request succeed, with local - not (but on local server I receive information).

Ok, so you are sending the Request to a PhP File?
Are you sure that your LocalWebserver can handle everything?

In the response function “EventRequestComplete” you can check if your Response is valid with “Response.IsValid()”.
You can also check the Response Code “Response->GetResponseCode()”.

Here is how my HTTPRequest looks like. Maybe that helps you:


TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
	HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
	HttpRequest->SetURL(TEXT("http://127.0.0.1/gameupdatesession.php"));
	HttpRequest->SetVerb(TEXT("POST"));
	HttpRequest->SetContentAsString(PostData);
	HttpRequest->OnProcessRequestComplete().BindUObject(this, &AHTTP_LoginAndID::OnUpdateSessionRequestComplete);

	if (!HttpRequest->ProcessRequest())
	{
		GEngine->AddOnScreenDebugMessage(1, 600.0f, FColor::Green, TEXT("Request failed at start!"));
	}

I can’t really tell what is going wrong on your side. Have you tested it with a simple php file like i did?

I have a primitive socket server application. I don’t have any php pages. Response.IsValid() is false in my case as well as bSucceeded. And Response->GetResponseCode() is not available for me (ue version 4.4).

Hmpf, i’m new to HTTPRequests so i don’t think i can outline your problem :confused:
Have you tested if the Request fails on beginning? Like i did with the if Clause?
The ResponseCode should be available after the Response is valid because i
use 4.4 too and i got the Code.

If your code works on google but not on your own mashine there needs to a
difference between those too ): But sadly i can’t tell you what it is.

But maybe another guy on this forum could have a look at this thread.
Feels a bit empty here :confused:

Yes, request is sended.
Actually I hoped that someone will say that HTTPRequests not works on local machine ). But if you say that on your machine everything works fine, I think that this is my server problems. Anyway, thank you for help ).

hello,can you please write an example of PostData which is as FString ,I do not now the format.I use Json. Does the String like PostData="Value= 1 "???Can you give me a help???

hello.can you give me your code?

if you are looking to pass JSON data JhonMax you would want to use FJsonObject and then serialize / deserialize the json with FJsonSerializer. If you post the actual code you have tried I can point you in the right direction.