Http Request on iOS

I am trying to perform a very simple GET request on iOS. I just want to get the response from a PHP page that I have created to access a database. The code works perfectly on Andoid, Windows and OSX but causes a crash immediately as it’s called on iOS. I’ve been trying to figure this out for about a month now and it’s killing me. I will be so incredibly happy if someone knows what is going wrong.

The code I’m using is below.

Header .h file:

//Send an HTTP Get request
UFUNCTION(BlueprintCallable, Category = "SBNetworking")
bool SendGetRequest(FString TheHost);

//this is called when data is received.
void HTTPOnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);

//This is an event callable in BP that fires when HTTP data is received
UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "Http Request Data Received"))
void HTTPRequestDataReceived(const FString& HttpData);

.cpp File:

//Perform a simple get request
bool ASandboxNetworkActor::SendGetRequest(FString TheHost){
	FHttpModule* HttpMod = &FHttpModule::Get();
	if (!HttpMod) { return false; }
	if (!HttpMod->IsHttpEnabled()) { return false; }

	FString TargetHost = TheHost;
	TSharedRef <IHttpRequest> Request = HttpMod->CreateRequest();
	Request->SetHeader("User-Agent", "SandboxNetworkAgent/1.0");
	Request->SetHeader("Content-Type", "text/html");

	Request->OnProcessRequestComplete().BindUObject(this, &ASandboxNetworkActor::HTTPOnResponseReceived);
	if (!Request->ProcessRequest()) { return false; }

	return true;

void ASandboxNetworkActor::HTTPOnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)

void HTTPRequestDataReceived(const FString& HttpData){

If there is another way of doing this I am totally open to suggestions!!! I tried creating a fresh project and adding the code to test it out. It crashed as expected. I have “HTTP” added to my public and private dependencies in build.cs and #include “Http.h” in my header file. Once again it works on all platforms I’ve tested but iOS.

Here is the crash log:

Crash log txt file

Thank you so much for any help you can offer. I am truly desperate and cannot move any further on 2 of my projects without this functionality.

The crash stack dump are not very helpful, they missing symbol data (what address correspond to what line in cpp file) you can see those in iOS libraries

2   libsystem_pthread.dylib       	0x226430f9 pthread_cond_timedwait + 45

but not in UE4 modules, all you get is memory address

4   FirstPersonSandbox49          	0x03563a91 0x4000 + 55966353

Without that this crash raports tells nothing

Do you use launcher iOS UE4 build? If not, try to compile debug build and run it, it should have symbols then… i think i never worked with iOS or OSX. Without that it hard to debug crashes

Alternativly you could try see logs (again i don’t know how you do it in iOS), this might be some controlled crash (UE4 is design to crash it self in controllable way when issue is detected, insted of letting it crash it self without much data), like assert error, not to mention looking on stack dump

0   libsystem_kernel.dylib        	0x225a1c84 __pthread_kill + 8
1   libsystem_pthread.dylib       	0x22643b47 pthread_kill + 63
2   libsystem_c.dylib             	0x225380c5 abort + 109
3   FirstPersonSandbox49          	0x00493ee5 0x4000 + 4783845

it look like UE4 killed it self (UE4 clearly called function “abort” by itself) so it might left his “suicide note” in logs :stuck_out_tongue:

Hey thanks so much for the response! I grabbed those crash logs from the device manager in XCode which is all i could find. I think it attempts to symbolify it. If there is some way to get the symbol data that would be more helpful then please let me know and I will get it right away!

I have tried building/running from XCode. I build/run the editor in XCode then launch on the device from the editor. I have also tried packaging with no luck. I can get other C++ code to work on iOS but this function just crashes instantly.

If there is any way to get better debug information from these crashes please let me know! I had no idea what to make of these crash logs and was hoping they would be of some use.

Do you know how (or if) I can find the UE4 suicide note from the iPad? That would be amazingly helpful :slight_smile:

Oh wow you are amazing thank you so much for pointing out NSLog!! I am brand new to OSX and apparently there is a little triangle at the bottom left of the device manager that shows the console. I am not sure if I enabled it in Xcode → preferences or if it was there all along. It’s showing now and that’s what matters. Now I have an actual error to work with!

The error begins right after “Network Actor Spawned”:
NSLog output txt file

It looks like

"Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file." 

is the source of the problem. It looks like the HTTP request was blocked and is causing a crash. What do I need to do to my Info.plist file to allow this?

Well you would need to build debug version of engine, which means you need to build it from source. But try to get log first, since for me looking on what i can read from this crash now it is controlled crash.

i don’t know how to get the logs in iOS, i don’t know how devlopment looks there, but i my guess is you can watch logs in some of iOS debug tools in XCode. In case of Android UE4 it prints logs in to central system log called logcat, which you can see using ADB or Android monitor tool, so the same probably is with iOS, there might be tool for that. I trying to google but i can’t find much, this might direct you somewhere:

UE4 definitly uses NSLog to print anything:

Oh wow I finally got it to work. Thank you so much for showing me NSLog! That gave me the output I needed to figure out what was actually going wrong! I needed to allow an exception for the connection I’m making in the plist.

I just added this to the “additional plist data” section in project settings->ios (this is for for example):

<key>NSAppTransportSecurity</key><dict><key>NSExceptionDomains</key><dict><key></key><dict><!--Include to allow subdomains--><key>NSIncludesSubdomains</key><true/><!--Include to allow HTTP requests--><key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/><!--Include to specify minimum TLS version--><key>NSTemporaryExceptionMinimumTLSVersion</key><string>TLSv1.1</string></dict></dict></dict>

I removed the line breaks from above. You are amazing !

Edit: I am converting this to answer and marking it for future people having this problem.

Ok then i conver my comment to anwser then

Nice! For some reason this isn’t the answer, which could be confusing to readers. Could you mark this as the answer?

About HTTP, maybe get some inspiration from this: