x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

IHttpRequest::ProcessRequest on Android Crash

I'm trying to make HTTP-request on Android build.

 void UHttpAdapter::SendHttpRequest(const FString& URL, EHttpMethodType Method, const FString& Content, FOnHttpRequestSuccess Success, FOnHttpRequestFailed Failed)
 {
     auto MethodName = UCommonUtils::GetEnumValueAsString(TEXT("EHttpMethodType"), Method);

     auto OnResponseReceived = [Success, Failed](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
         {
             UE_LOG(LogHttpAdapter, Log, TEXT("Response from %s : %s"), *Request->GetURL(), bWasSuccessful ? TEXT("success") : TEXT("failed"));
 
             if (bWasSuccessful) 
                 Success.ExecuteIfBound(Response->GetContentAsString());
             else
                 Failed.ExecuteIfBound();
         };
 
     auto Http = &FHttpModule::Get();
 
     auto Request = Http->CreateRequest();
 
     Request->SetURL(*URL);
     Request->SetVerb(*MethodName);
     Request->SetHeader(TEXT("User-Agent"), TEXT("X-UnrealEngine-Agent"));
     Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
     
     if (Method == EHttpMethodType::HM_POST)
         Request->SetContentAsString(*Content);
 
     Request->OnProcessRequestComplete().BindLambda(OnResponseReceived);
 
     if (!Request->ProcessRequest())
         Failed.ExecuteIfBound();
 
     //auto Response = Request->GetResponse();
 
     UE_LOG(LogHttpAdapter, Log, TEXT("Request to %s by %s"), *Request->GetURL(), *MethodName);
 }


But app will crashed on Request->ProcessRequest() call on Android.

Windows build and in Editor works correct.

I thinks about problem with libcurl.. but all links are correct

Someone can hepl me with this? Maybe I need use some another way to call http-request?

Also.. Socket connection by FTcpSocketBuilder().Build()->Connect(IpAddr) works correct. This is not a problem with network.

Product Version: UE 4.18
Tags:
more ▼

asked Dec 19 '17 at 02:12 AM in C++ Programming

avatar image

DantaliaN00
16 6 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Oh.. it... was.......

I found error - for some reason MethodName in Request->SetVerb(*MethodName) was incorrect on Android builds, but everything Ok in Editor.

more ▼

answered Dec 19 '17 at 03:33 AM

avatar image

DantaliaN00
16 6 6

avatar image Lord7even Dec 15 '18 at 06:10 PM

Could you tell me a bit more how you set this up? Somehow this is not working on my end and I'm searching for houers for a solution. It works well on Windows and the Mobile Preview Window but on the actual Android it seams that the http module is not working. I get absolute no answer from the request. Could this be a problem with the signature of the app?

avatar image DantaliaN00 Dec 15 '18 at 08:27 PM

here is my full solution

avatar image DantaliaN00 Dec 15 '18 at 08:29 PM

header

 #pragma once
 
 #include "CoreMinimal.h"
 #include "HttpAdapter.generated.h"
 
 DECLARE_LOG_CATEGORY_EXTERN(LogHttpAdapter, Log, All);
 
 UENUM(BlueprintType)
 enum class EHttpMethodType : uint8
 {
     GET         UMETA(DisplayName = "GET"),
     POST     UMETA(DisplayName = "POST")
 };
 
 DECLARE_DYNAMIC_DELEGATE_OneParam(FOnHttpRequestSuccess, FString, Response);
 DECLARE_DYNAMIC_DELEGATE(FOnHttpRequestFailed);
 
 UCLASS()
 class MOBAGAME_API UHttpAdapter : public UObject
 {
     GENERATED_BODY()
 
 public: 
     UFUNCTION(BlueprintCallable, Category = "HttpAdapter")
         static void SendHttpRequest(const FString& URL, EHttpMethodType Method, const FString& Content, FOnHttpRequestSuccess Success, FOnHttpRequestFailed Failed);
 };
avatar image DantaliaN00 Dec 15 '18 at 08:30 PM

source

 #include "HttpAdapter.h"
 #include "HttpModule.h"
 #include "IHttpResponse.h"
 #include "Utils/CommonUtils.h"
 
 DEFINE_LOG_CATEGORY(LogHttpAdapter);
 
 void UHttpAdapter::SendHttpRequest(const FString& URL, EHttpMethodType Method, const FString& Content, FOnHttpRequestSuccess Success, FOnHttpRequestFailed Failed)
 {
     auto MethodName = UCommonUtils::GetEnumValueAsString(TEXT("EHttpMethodType"), Method);
 
     auto OnResponseReceived = [Success, Failed](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
         {
             if (bWasSuccessful) 
                 Success.ExecuteIfBound(Response->GetContentAsString());
             else
                 Failed.ExecuteIfBound();
         };
 
     auto Http = &FHttpModule::Get();
 
     auto Request = Http->CreateRequest();
 
     Request->SetURL(*URL);
     Request->SetVerb(*MethodName);
     Request->SetHeader(TEXT("User-Agent"), TEXT("X-UnrealEngine-Agent"));
     Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
     
     if (Method == EHttpMethodType::POST)
         Request->SetContentAsString(*Content);
 
     Request->OnProcessRequestComplete().BindLambda(OnResponseReceived);
 
     if (!Request->ProcessRequest())
         Failed.ExecuteIfBound();
 }

avatar image Lord7even Dec 16 '18 at 05:05 PM

wow, thank you very much! Very kind of you to share your code. mine looks not that different from yours. I'll try to use your code directly in the project I'm working on. Right now I have the code in a plugin which might be a problem

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question