Internal Server Error when making POST request (traced to Content-Length, but unable to debug) - post

I have a Windows application that makes a POST request using WinHTTP. It sends some custom headers and a CSV file in the body of the request.
It has been working fine when sending the request to localhost (http://127.0.0.1), but the remote server returns Status 500 - Internal Server Error.
However, the exact same request made via Postman to the remote server returns Status 200 - OK.
I have copies of the headers being sent from both applications. The only difference I can see is that, when sending via Postman, the value of Content-Length is always 20 greater than the header sent using WinHTTP. This is regardless of the actual size of the file, so the difference is always the same.
I don't know if this is to do with the way each application parses the CSV file, but neither is being zipped or anything like that.
If I manually change the value of Content-Length in Postman to match that being sent by WinHTTP, it throws the same 500 error, so I can actually replicate the error by bodging the value of Content-Length.
Therefore, I can only presume that the 500 error is being caused by a dodgy Content-Length header being generated by WinHTTP.
No data is being sent before the headers. There are no overly useful logs on the server, only the fact that an internal server error was thrown and the date/time it happened.
Is this problem likely to lie with WinHTTP, or is there a server configuration that needs to be changed?
I am unable to understand why one method returns 200 - OK and the other 500 - Internal Server Error, except for something to do with the Content-Length header.

Related

Fetch html response is not full via gatling,why?

I call a http request,The reponse is html,but gatling get the response is incomplete.What should I do
I think a part of I need that is gatling supported resources.It is under the tag 'table'.
The server may not be returning the complete response due to an error or a problem with the server-side code. In this case, you should check the server logs to see if there are any errors, and you should also check the HTTP response headers to see if there are any indications of what went wrong.
The HTTP request may be failing or being blocked by a firewall or other network security device. In this case, you should check the network logs to see if the request is being sent and received successfully, and you should also check any network security settings to ensure that the request is not being blocked.
The HTML response may not be well-formed or may be missing some elements, such as the 'table' element you mentioned. In this case, you should validate the HTML using a tool such as the W3C HTML Validator, and you should also check the HTML source to ensure that all required elements are present.
User issue, as concluded on the Gatling community forum.

URLResponse cached although response's cache-control header is set to no-cache

In my iOS app I want to cache images that are requested from different destinations. For downloading images I use URLSessionDataTasks with the default caching mechanism provided by URLSession.shared, which makes use of the NSURLRequestUseProtocolCachePolicy.
The caching works basically fine. Responses are being cached and cache headers like etag and cache-control "max-age" are correctly being handled. But if the server responds with the cache-control header set to "no-cache", the URLCache of the URLSession is still caching the image. I can access the cached response via URLCache.shared.cachedResponse(for: request) and also a new data task with the same request will return time image from the cache (which I validated by using Charles proxy and I'm not seeing the request I am awaiting).
Why isn't it correctly handling the respond's cache header? Do I need to manually check the respond's cache headers?
The no-cache directive doesn't mean "don't store it in the cache". Rather it instructs the cache not to serve a cached response without validating with the server first. The [RFC7234][1] specification says the following regarding the no-cache directive.
The "no-cache" response directive indicates that the response MUST NOT
be used to satisfy a subsequent request without successful validation
on the origin server. This allows an origin server to prevent a cache
from using it to satisfy a request without contacting it, even by
caches that have been configured to send stale responses.
If the no-cache response directive specifies one or more field-names,
then a cache MAY use the response to satisfy a subsequent request,
subject to any other restrictions on caching. However, any header
fields in the response that have the field-name(s) listed MUST NOT be
sent in the response to a subsequent request without successful
revalidation with the origin server. This allows an origin server to
prevent the re-use of certain header fields in a response, while still
allowing caching of the rest of the response.
So what will happen is that for "fresh" responses with the no-cache directive, a conditional request will be sent to verify whether the stored response can be used. If the response is still valid, the server will send a 304 - Not Modified response. Upon receiving the 304 response, the cache will serve the stored response with the no-cache directive. If the stored response is no longer valid, the server will send a new response.
[1]: https://www.rfc-editor.org/rfc/rfc7234#section-5.2.2

Wrong content-type received (AFNetworking bug)?

I send JSON response via AFNetworking from server to my app request. Also it's one script on server (php) and one DB (MySQL).
When I make requests to different tables (within the same DB) - comes valid response (JSON), but from only one table comes "image/jpeg" (afnetworking says me that) ... although the content-type on the server is correctly configured (header('Content-Type: application/json; charset=utf-8'); in .php).
What could be the problem?
Applied to a support - said they sent the correct headers (JSON)...why then AFNetworking sees the header image/jpeg?
ADDED SCREENSHOT OF CHROME DEV TOOL (correct json here):
But AFNetworking says:

nginx strips last-modified and if-modified-since headers but my rails app needs them

My Rails 3.2 app uses — via #stale? — If-Modified-Since HTTP header in the request and Last-Modified header in the response to decide whether it should generate some data dynamically. This works extremely well in development (whether using webrick or unicorn_rails) as curl -D headers.txt shows that if the correct If-Modified-Since value is provided a 304 response is sent, while the Last-Modified header is otherwise sent along the request data.
Unfortunately once deployed behind nginx, neither If-Modified-Since (providing the correct header value) is passed to unicorn — and thus the Rails app — nor Last-Modified is propagated to the client: the request is unconditionally generated and the response never contains the proper headers.
It turns out nginx was actually not stripping anything. Instrumentation showed that If-Modified-Since was received by the controller. Rails #stale? was receiving a request containing bad results, which resulted in a nil argument, swallowing it silently and subsequently ignoring comparisons to If-Modified-Since and positioning Last-Modified to nil.

HttpClient automatically retires before the response is received from server

I'm come upon a wierd problem with java HttpClient library.
Specifically the library automatically retries my request (POST requests)
even before the response is received from the server. Moreover the weirder problem
is that this only happens on specific hosts (machines).
So the end result is if a post request succeeds, then there may be an exact same
post request coming to the server which the server can't handle. Now, I do want
the retry behavior, but it should behave intuitively.
Anyone faced this kind of problem before, or is there a way to configure
http client to wait for a specific time before retrying. I'm not sure what going
wrong here.
Do you have a methodretryhandler set for your HttpClient? As in:
DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler(10, true);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler);
That is where retries would originate and you could debug and see what response headers it's receiving if any, etc.
Have you tried using a firefox http monitor or ethereal or similar to look through your http requests and responses and ensure that what you believe is happening is actually hapening?

Resources