I wrote a simple Grizzly/Jersey application, which you can find here:
https://github.com/boldt/stackoverflow-14526627
I want to post some form data:
curl -X POST -F "name=test" -i http://localhost:9999/files
I'm getting the following response:
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Fri, 25 Jan 2013 16:51:18 GMT
Transfer-Encoding: chunked
As you can see, the header is doubled, first a 100 Continue followed by a 200 OK. Is doesn't makes sense to get the 100 Continue.
Any suggestions?
This is normal. Curl is following the HTTP 1.1 spec. You are doing a POST which means you are going to be sending data to the server. Curl is sending a request header to the server with "Expect: 100-continue" in it.
This tells the server that the client wants permission to send a POST document and if the server responds with HTTP/1.1 100 Continue, then client sends the document (your form pairs in this case) otherwise the server may reject it for whatever reason with HTTP/1.1 417 Expectation Failed and this allows the client to not waste time sending lots of data possibly if it will be rejected.
There is nothing wrong with the two headers.
Read about the Expect header.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Check your request headers. You are probably sending HTTP Expect with curl.
curl -vv -X POST -F "name=test" -i http://localhost:9999/files
Related
It's my first time configuring load balancer and I am facing an issue where my Java application is returning error status code 400 when checking specific url. The expected result when calling following command (curl -I --verbose --noproxy * -H Host: -H User-Agent: -H Accept: http://test.company.com:8080/accountBatch/jsf/landingPage.xhtml) is status 200. Instead, I am receiving following error despite service being available:
< HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
Application is not using spring boot; additionally, its using tomcat 7.0.
If I want to return status 200 for the url above, is there any additional configuration needed? Sadly I am unable to find any documentation regarding non-spring boot applications.
Your curl request is broken - hence you get a 400 response. You need to provide a value for at least the Host header (or don't explicitly set it) and possible the other headers as well.
My team and I have a Tomcat server running a Restfull webservice, implemented using RestEasy:
#POST
#GZIP
#Path("/capture")
#Consumes(MediaType.APPLICATION_JSON)
Response RecieveData(#GZIP RecievingData recievingData);
We need to make compressed post to this service. The problem is we are not finding an implementation that works.
We tried using interceptors:
https://hc.apache.org/httpcomponents-client-4.2.x/httpclient/examples/org/apache/http/examples/client/ClientGZipContentCompression.java. But we were unable to capture the POST request Body and compress it.
We tried using the RestEasy client but it doesn´t seems to be compreesing the body of the Post Request: www.posttestserver.com/data/2016/01/06/15.33.391016591335
Finally we tried a customized class: https://gist.github.com/takumakei/913067. But we got a 400 error on the request:
HTTP/1.1 400 Bad Request [Content-Encoding: gzip, Content-Type:
text/html; charset=UTF-8, Date: Thu, 07 Jan 2016 10:07:05 GMT, Server:
Apache-Coyote/1.1, Content-Length: 66, Connection: keep-alive]
We are out of ideas and this supose to be a simple function for an HTTP Client. Any ideas?
OBS: Here is the RestEasy Proxy:
#POST
#GZIP
#Consumes(MediaType.APPLICATION_JSON)
public Response saveData(#GZIP RecievingData customer);
EDIT: Got some changes in the Firewall and the 3rd method changed to an error 400.
If using Tomcat why not add a RequestFilter that will pre-process received requests that contain header Content-Encoding: gzip and decompress it before the rest of the filter chain handles it?
EDIT:
I'm guessing your third option may actually have worked (snoop the network to verify), the issue was you got 403 - Forbidden response from the server. That's a problem with authorization not with the URL, request encoding, or anything else. The GZIP might actually be working for you right now.
EDIT:
Your latest output for HTTP response code 400 - Bad Request shows Content-Type: text/html. The Controller is expecting Content-Type: application/json, so the client did not set the ContentType as required by the Controller. Recheck your usage and config of the client code.
In the end I used the Resteasy framework for server and client to implement the GZIP compression.
Server side:
https://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html/gzip.html
Client Side:
https://docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/RESTEasy_Client_Framework.html
That worked for me.
I am writing a http server in java using ServerSocket and Socket respectively.
In specification it says that the request can be of "chunked" type. So how could I enable this option in any browser to test the parsing of the request?
You can easily make up the request on your own:
POST /search HTTP/1.1
Host: www.example.com
Transfer-Encoding: chunked
Content-Length: 25
000a
q=23456789
000a
0123456789
0005
01234
0
This request is split into three parts, and your server should receive q=23456789012345678901234 as the POST data.
Note: you need another CRLF at the end of the request, which this markup language cannot display.
AFAIK most desktop browsers don't send chunked requests because some web servers don't handle them correctly (or at all) and it's easier to calculate the length than to detect/guess/remember which servers support it.
The curl command-line tool can send chunked requests:
curl -v -d "name=value" --header "Transfer-Encoding: chunked" http://foo.com/bar
Worldpay (The payment processor from RBS) sends a HTTP Post to my website once a payment is accepted. Problem is - the Post isnt getting through and my server responds with one of the following 3 HTTP error's:
HTTP 408 (Timeout)
HTTP 405 (Not allowed)
Invalid status line >NULL<
Now when i Post something to the url from my test php script this works fine which leads me to believe the issue could be with the fact that the Post from them is created by Java:
POST /worldpay_success.html HTTP/1.0
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: www.mysite.com
Content-Length: 116
User-Agent: WJHRO/1.0 (WorldPay Java HTTP Request Object)
authAmountString=%26%23163%3B1.99&_SP.charEnc=UTF-8&desc=Test.....etc
Does anyone have any experience with this? After speaking to Worldpay they say my server is responding with a 408 Timeout after 0.1 seconds so it doesnt seem to be properly timeing out... Any help apreciated
Paul
Check 405 Method Not Allowed and Request Timeout. It shouldn't matter if the POST request is created from Java.
I want to fetch a web page from a ASP.NET site that is only accessible from within a session. I'm using Apache HttpClient. I first open the main page of the site, then I search for the link to the "goal" page, and then I fire up a GET request for the "goal" page. The problem is that when I get the response for the second GET request, I always get the same (first) page. If I open the site with Firefox or Google Chrome I get the "goal" page.
From the first response from the server I get the following headers:
HTTP/1.1 200 OK
Date: Sun, 12 Dec 2010 19:03:56 GMT
Server: Microsoft-IIS/6.0
Platform: Mobitel Pla.NET
Node: 4
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=0vpgd055cifko3mnw4nkuimz; path=/
Cache-Control: no-cache, must-revalidate
Content-Type: text/html; charset=utf-8
Content-Length: 7032
I inspected the traffic with WireShark and all headers look OK. I send the correct cookie back to the server on the second GET request.
I'm using Apache HttpClient. I have only one instance of DefaultHttpClient and I reuse that for the second request. I have BROWSER_COMPATIBILITY Cookie Policy.
Any ideas?
You need send back this header from the client (send back the cookie you received) in all your further requests:
Cookie: ASP.NET_SessionId=0vpgd055cifko3mnw4nkuimz; // and all other cookies
That should do the trick
I found my stupid mistake.
The mistake was that I was sending the second GET request to a link, without replacing the ampersand character codes.
Ex:
/(0vpgd055cifko3mnw4nkuimz)/Mp.aspx?ni=1482&pi=72&_72_url=925b9749-b7c7-4615-9f1a-9b613c344c82
That is wrong, because I send & instead of &
The RIGHT way to do it is:
/(0vpgd055cifko3mnw4nkuimz)/Mp.aspx?ni=1482&pi=72&_72_url=925b9749-b7c7-4615-9f1a-9b613c344c82