# Reading a file online

**URL:** <https://forums.unrealengine.com/t/reading-a-file-online/336882>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 29, 2015, 3:48pm UTC](https://forums.unrealengine.com/t/reading-a-file-online/336882 "2015-10-29T15:48:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sneppy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sneppy](https://forums.unrealengine.com/u/Sneppy)\
**Post date:** [October 29, 2015, 3:48pm UTC](https://forums.unrealengine.com/t/reading-a-file-online/336882/1 "2015-10-29T15:48:12Z")

</div>

I need to read a sequence of bytes stored in a basic txt file which can be found at a specific url.  
With a local file path I can use SaveFileToArray() function to store the bytes in a uint8 array, how can I do the same with the given file url?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [October 29, 2015, 4:43pm UTC](https://forums.unrealengine.com/t/reading-a-file-online/336882/2 "2015-10-29T16:43:28Z")

</div>

Fact that you can use http urls as files is a extra feature to make things comfitible, but in code they are 2 separate data channels with diffrent APIs.

UE4 has module to talk to HTTP server:

> **[HTTP](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/)**

This is entry point:

> **[FHttpModule::Get](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/FHttpModule/Get/)**
>
> Singleton-like access to this module's interface.

Create a http request:

> **[FHttpModule::CreateRequest](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/FHttpModule/CreateRequest/)**
>
> Instantiates a new Http request for the current platform

I returns request body which you can edit with those functions:

> **[IHttpRequest](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/Interfaces/IHttpRequest/)**
>
> Interface for Http requests (created using FHttpFactory)

Request is processed asynchronously so it does not lock the thread waiting for response from server, thats why you need to bind event which be called when responce been recived:

> **[IHttpRequest::OnProcessRequestComplete](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/Interfaces/IHttpRequest/OnProcessRequestComplete/)**
>
> Delegate called when the request is complete. See FHttpRequestCompleteDelegate

Once you set up the request you call ProcessRequest and HTTP module with do the rest:

> **[IHttpRequest::ProcessRequest](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/Interfaces/IHttpRequest/ProcessRequest/)**
>
> Called to begin processing the request.

And once it got reponce it will call function you binded with IHttpReponce argument from which you can read reponce data:

> **[IHttpBase](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/Interfaces/IHttpBase/)**
>
> Base interface for Http Requests and Responses.

> **[IHttpResponse](https://docs.unrealengine.com/5.1/en-US/API/Runtime/HTTP/Interfaces/IHttpResponse/)**
>
> Inteface for Http responses that come back after starting an Http request

Here you have nice simple example from engine source code how to use it (Note how OnProcessRequestComplete function arguments, your function needs to be exactly the same, only name can be different):

[https://github.com/EpicGames/UnrealEngine/blob/a27ad66f0a075f3b74ef8f68a4b2b0da4882425e/Engine/Source/Runtime/Online/HTTP/Private/HttpTests.cpp](https://github.com/EpicGames/UnrealEngine/blob/a27ad66f0a075f3b74ef8f68a4b2b0da4882425e/Engine/Source/Runtime/Online/HTTP/Private/HttpTests.cpp)

If you don’t know how HTTP works (which if you ever worked with PHP and web devlopment you should know) then learn about it because it will be very useful here:

> **[HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol)**
>
> The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access, for example by a mouse click or by tapping the screen in a web browser.
> Development of HTTP was initiated by Tim Berners-Lee at CERN in 1989 and summarized in ...

And lastly if you gonna use HTTP module, remember to add “HTTP” in to depency in build scipt same as you do with “AIModule”, otherwise you gonna have linker errors

---

<div class="post-metadata">

**Author:** ![Vahid](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vahid](https://forums.unrealengine.com/u/Vahid)\
**Post date:** [January 18, 2017, 7:31am UTC](https://forums.unrealengine.com/t/reading-a-file-online/336882/3 "2017-01-18T07:31:26Z")

</div>

Hello, Thanks for your description, I’ve a question:  
I’m trying to add support for external login for my App (I’m trying to add WeChat QR scan login) It totally use the URL to handle process, I can show the QR code in UE web browser and i can login successfully but the login is totally in that browser, I need to login outside of browser too, do you have any suggestion how i can do that ? (Now i can manually login to my server with username & password with and POST verb)…  
Thank you

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [January 26, 2017, 1:02am UTC](https://forums.unrealengine.com/t/reading-a-file-online/336882/4 "2017-01-26T01:02:47Z")

</div>

You know how cookie sessions work right? Somehow you need to catch the session id and use it with HTTP to by sending cookie (first learn how cookies works). Noe here the problem, it seem theren ot really way to get a cookie from web browser widget, you would need to get some session key with diffrent method, liek sending key somehow and catcxh it web browser event and use it later in HTTP. Best sollution would be if you use login without using web browser.
