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"

Problem Http Request

I want to do a Http Request, and I'm using a blueprint function library, but when I have the response, UE4 crash. Could you tell why?

My code is:

Cpp:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "ProyectoImag.h"
 #include "HTTP.h"
 #include "JSON.h"
 #include <string>
 #include "Engine.h"
 #include <iostream>
 #include "HttpConnections.h"
 
 /*Http call*/
 FString UHttpConnections::MyHttpCall()
 {
 
     TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
     /*This is the url on which to process the request*/
     Request->SetURL("http://localhost/basic/web/index.php?r=objetos%2Frecoger");
     //Get a la base de datos
     Request->SetVerb("GET");
     Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
     Request->SetHeader("Content-Type", TEXT("application/json"));
     Request->ProcessRequest();
     FHttpResponsePtr Response;
     return Response->GetContentAsString();
 }



.H:

 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "HTTP.h"
 #include "HttpConnections.generated.h"
     /**
     *
     */
     UCLASS()
     class PROYECTOIMAG_API UHttpConnections : public UBlueprintFunctionLibrary
     {
         GENERATED_BODY()
     
     public:
     
         FHttpModule* Http;
         UFUNCTION(BlueprintPure, Category = "Arch Functions")
             static FString MyHttpCall();
     };




Bug:

 MachineId:DAA38AEF408D370034AA579C2E55D70B
 EpicAccountId:90f2d31f6fb440cb997e3afdffac214e
 
 Unknown exception - code 00000001 (first/second chance not available)
 
 "Assertion failed: IsValid() [File:C:\Epic Games\4.10\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h] [Line: 739] 
 "
 
 UE4Editor_Core!FDebug::AssertFailed() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\core\private\misc\outputdevice.cpp:374]
 UE4Editor_ProyectoImag!UHttpConnections::MyHttpCall() [c:\users\alejandro perez\desktop\proyectoimag\source\proyectoimag\httpconnections.cpp:33]
 UE4Editor_ProyectoImag!UHttpConnections::execMyHttpCall() [c:\users\alejandro perez\desktop\proyectoimag\source\proyectoimag\httpconnections.h:16]
 UE4Editor_CoreUObject!UFunction::Invoke() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\class.cpp:4198]
 UE4Editor_CoreUObject!UObject::CallFunction() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:484]
 UE4Editor_CoreUObject!UObject::ProcessContextOpcode() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1755]
 UE4Editor_CoreUObject!UObject::execLet() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1558]
 UE4Editor_CoreUObject!UObject::ProcessInternal() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:698]
 UE4Editor_CoreUObject!UFunction::Invoke() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\class.cpp:4198]
 UE4Editor_CoreUObject!UObject::ProcessEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1053]
 UE4Editor_Engine!AActor::ProcessEvent() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\actor.cpp:580]
 UE4Editor_Engine!FLatentActionManager::TickLatentActionForObject() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\latentactionmanager.cpp:169]
 UE4Editor_Engine!FLatentActionManager::ProcessLatentActions() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\latentactionmanager.cpp:77]
 UE4Editor_Engine!AActor::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\actor.cpp:745]
 UE4Editor_Engine!AActor::TickActor() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\actor.cpp:730]
 UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\actor.cpp:107]
 UE4Editor_Engine!FTickFunctionTask::DoTask() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\ticktaskmanager.cpp:141]
 UE4Editor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\core\public\async\taskgraphinterfaces.h:779]
 UE4Editor_Core!FTaskThread::ProcessTasks() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\core\private\async\taskgraph.cpp:539]
 UE4Editor_Core!FTaskThread::ProcessTasksUntilQuit() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\core\private\async\taskgraph.cpp:340]
 UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\core\private\async\taskgraph.cpp:1140]
 UE4Editor_Engine!FTaskGraphInterface::WaitUntilTaskCompletes() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\core\public\async\taskgraphinterfaces.h:212]
 UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\ticktaskmanager.cpp:285]
 UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\ticktaskmanager.cpp:1206]
 UE4Editor_Engine!UWorld::RunTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\leveltick.cpp:701]
 UE4Editor_Engine!UWorld::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\engine\private\leveltick.cpp:1150]
 UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\editor\unrealed\private\editorengine.cpp:1347]
 UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\editor\unrealed\private\unrealedengine.cpp:361]
 UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\launchengineloop.cpp:2427]
 UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\launch.cpp:142]
 UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
 UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.10\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
 UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
 kernel32
 ntdll

Thanks.

Product Version: UE 4.10
Tags:
more ▼

asked Jul 04 '16 at 05:41 PM in C++ Programming

avatar image

perezal
1 1 1 3

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

Reason is this:

  FHttpResponsePtr Response;
  return Response->GetContentAsString();

You create empty response pointer which is null and make a call of it, so engine stops when it checks its validity (IsValid())

This is not how you should use HTTP API, it's asynchronous as you not sure when you get reponce.... if you even get one. You need to bind to event to request and you get delegate for it from OnProcessRequestComplete() function, here you got example from engine code (this code is to test this API):

https://github.com/EpicGames/UnrealEngine/blob/dff3c48be101bb9f84633a733ef79c91c38d9542/Engine/Source/Runtime/Online/HTTP/Private/HttpTests.cpp#L17

 TSharedPtr<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
 Request->OnProcessRequestComplete().BindRaw(this, &FHttpTest::RequestComplete);
 Request->SetURL(Url);
 if (Payload.Len() > 0)
 {
     Request->SetContentAsString(Payload);
 }
 Request->SetVerb(Verb);
 Request->ProcessRequest();


Hmmm i think by returning this delegate in the end of blueprint node you should able to bind it in blueprints

more ▼

answered Jul 05 '16 at 02:41 PM

avatar image

Shadowriver
34.5k 917 164 1094

avatar image Shadowriver Jul 05 '16 at 06:32 PM

Well make a delegate and make node return it, it will create red squere event which let you bind event same as set timer node does

https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/

(comments are locked)
10|2000 characters needed characters left

I don't know what I need to add to my new code because I don't know how to get MessageBody in a node, I'm using delegates but it's difficult to understand it and the code which you can find below has errors and I don't know why.

Could you tell me how would be the code?

.H:

 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "Runtime/Online/HTTP/Public/Http.h"
 #include "HttpConnections.generated.h"
 
 DECLARE_DYNAMIC_DELEGATE(Delegate, FString, Messagebody);
 
 UCLASS()
 class PROYECTOIMAG_API UHttpConnections : public UBlueprintFunctionLibrary
 {
     GENERATED_BODY()
 
 public:
 
     FHttpModule* Http;
     UFUNCTION(BlueprintCallable, Category = "Arch Function")
         static void MyHttpCall();
 
     UPROPERTY(BlueprintReadWrite, Category = "Delegate", VisibleAnywhere)
         Delegate Resultado;
 
     void RequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
 
 public:
     UFUNCTION(BlueprintPure)
         void Retrieve(Delegate& Messagebody);
 };

.cpp:

 #include "ProyectoImag.h"
 #include "Runtime/Online/HTTP/Public/Http.h"
 #include "Engine.h"
 #include "HttpConnections.h"
 
 
 /*Http call*/
 void UHttpConnections::MyHttpCall()
 {
     
     TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
     /*This is the url on which to process the request*/
     //Get a la base de datos
     Request->SetVerb("GET");
     Request->SetHeader("Content-Type", TEXT("application/json"));
     Request->SetURL("http://localhost/basic/web/index.php?r=objetos%2Frecoger");
     Request->OnProcessRequestComplete().BindUObject(this, &UHttpConnections::RequestComplete);
     Request->ProcessRequest();
 }
 void UHttpConnections::RequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) 
 {
     FString Messagebody;
     Messagebody=Response->GetContentAsString();
     Resultado.Broadcast(Messagebody);
 }
 void UHttpConnections::Retrieve(const ResultadoDelegate& Messagebody)
 {
     Resultado = Messagebody;
 }


Thanks.

more ▼

answered Jul 06 '16 at 12:07 PM

avatar image

perezal
1 1 1 3

avatar image emrahgunduz Jul 06 '16 at 01:08 PM

delegates need "F" in front while naming. also, you must specify the variable count.

 DECLARE_DYNAMIC_DELEGATE_OneParam(FDelegate, FString, Messagebody);
(comments are locked)
10|2000 characters needed characters left

Could you tell me the lines that I have to add to obtain my parameter Messagebody? I think that I have to bind and then I have to call the parameter, but I don't know how to do it.

 #pragma once
 
 #include "Kismet/BlueprintFunctionLibrary.h"
 #include "Runtime/Online/HTTP/Public/Http.h"
 #include "Runtime/Core/Public/Delegates/Delegate.h"
 #include "HttpConnections.generated.h"
 
 DECLARE_DELEGATE_OneParam(FDelegate, FString, Messagebody)
 
 UCLASS()
 class PROYECTOIMAG_API UHttpConnections : public UBlueprintFunctionLibrary
 {
     GENERATED_BODY()
 
 public:
 
     FHttpModule* Http;
     UFUNCTION(BlueprintCallable, Category = "Arch Function")
         static void MyHttpCall();
 
     void RequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
 
     UFUNCTION(BlueprintPure)
         FString Retrieve(FString Messagebody);
 
     UPROPERTY(BlueprintAssignable)
         FDelegate Resultado;
     
 };

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "ProyectoImag.h"
 #include "Runtime/Online/HTTP/Public/Http.h"
 #include "JSON.h"
 #include <string>
 #include "Engine.h"
 #include <iostream>
 #include "HttpConnections.h"
 
 /*Http call*/
 void UHttpConnections::MyHttpCall()
 {
     TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
     /*This is the url on which to process the request*/
     //Get a la base de datos
     Request->SetVerb("GET");
     Request->SetHeader("Content-Type", TEXT("application/json"));
     Request->SetURL("http://localhost/basic/web/index.php?r=objetos%2Frecoger");
     Request->OnProcessRequestComplete().BindUObject(this, &UHttpConnections::RequestComplete);
     Request->ProcessRequest();
 }
 void UHttpConnections::RequestComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) 
 {
     FString Messagebody;
     Messagebody=Response->GetContentAsString();
 
 }
 FString UHttpConnections::Retrieve(FString Messagebody)
 {
 
 }

Thanks :)

more ▼

answered Jul 07 '16 at 09:00 AM

avatar image

perezal
1 1 1 3

(comments are locked)
10|2000 characters needed characters left
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