Jump to content

Rhaoma

New Members
  • Posts

    4
  • Joined

  • Last visited

  • Days Won

    1

Rhaoma last won the day on March 14

Rhaoma had the most liked content!

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Rhaoma's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. Hi No offense taken at all ; I was just annoyed at myself with the fact that I spent most of last night debugging something, that seemingly fixed itself next morning (as is often sadly the case) Thats propably why my reply seemed angry. I apologize. As for the actual problem I have no idea what caused the initial behaviour. Now I get perfectly reasonable results regardless of whether i use cURL or file_get_contents; I therefore thought it was fitting to mark your reply as the solution, since: was exactly what was needed. Best, David
  2. Well originally I of course calculated Content-Length based on my actual POST-/multipart-data size . I should of course have specified that the given excerpt was psudeo code. EDIT: I just rechecked, and retried the code i posted above, and it works 😕 - even if the content-length is 100 - the request gets posted. I'll have to agree with @jodunno that I simply wrote some shit code; where I do not know though
  3. If anyone stumbles into the same problem I suggest moving server requests to php cURL. Making the request through curl fixes things, as curl automatically sets the content-length header correctly - for some reason... Unsatisfying, that I couldn't figure out why file_get_contents failed, but at least there is a fix to some extent
  4. Hi I'm acessing a backend server from php through file_get_contents. For most requests manually setting the Content-Length header has not been neccessary, but when trying to send multipart-form-encoded data, PHP seemingly didn't automatically add the Content-Length header. I thought no biggie, I will just add it manually in the stream_context_create call along with my other headers. This however failed miserably; it seems that manually adding the Content-Length header, causes the HTTP request to not get sent (verified through wireshark). This is the case for all calls, whether multipart or not - the request simply doesn't get dispatched. PHP just freezes/hangs until the specified timeout, and then throws following warning: "WARNING: file_get_contents(http://127.0.0.1:83/items): Failed to open stream: HTTP request failed!". I have independently checked that, if the request was to be dispatched through other means than PHP the request succeeds. The below sample code hangs when adding the 'Content-Length: <some value>" header array item, otherwise works perfectly fine. $headers = array( 'Authorization: Bearer '.$User->GetAuthString(), 'Accept: application/json', 'Content-Length: 100' ); $content = json_encode($_POST); $url = getBackendURL().'/items'; // Forward request to backend $context = stream_context_create( array( 'http' => array( 'method' => $method, 'header' => $headers, 'content' => $content, 'timeout' => 300 ) ) ); $reply = file_get_contents($url, false, $context); Any suggestion as to what is going on? I have tested everything i have come across on the web, header string instead of array, HTTP 1.0 instead of 1.1, "Connection: close" etc. I am at a loss Regards
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.