feign-okhttp post request with url query parameters - spring-boot

I currently have replaced httpurlconnection to feign-okhttp in my projects. I use the following edition:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>9.6.0</version>
</dependency>
but I got a problem when I post this url: "http://gclife-platform-service:20000/v1/user/login/log?userId=ea9dd2f707a54b11b03193c35b2ad3a4&error=SUCCESS"
The log from server side as following:
Received [1.1
cache-control: no-cache
...
But "Received [1.1" should be:
Received [POST v1/user/login/log?userId=ea9dd2f707a54b11b03193c35b2ad3a4&error=SUCCESS HTTP/1.1
So this caused the parse problem.
2018-05-05 10:10:04.076 DEBUG 6525 --- [io-20000-exec-9] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
when I post url with no query parameters like "http://gclife-platform-service:20000/v1/message/sms/verifycode/check", I got:
Received [POST /v1/message/sms/verifycode/check HTTP/1.1
This is the correct result.
How can I get the correct log like this? Can anyone help? Thanks.

This exception can occur when you try to execute https request from client on endpoint which isn't https enabled. Client will encrypt request data when server is expecting raw data.
Change https:// to http:// in your client url.

I made the same mistake.
print Feign header and find Content-Length was duplicate definition.

Related

For Jmeter Bearer authorization token request, Getting org.apache.http.conn.HttpHostConnectException

I am sending a HTTPS request which needs a Bearer token. I have added a Header Manager to my HTTP request in JMeter and defined NAMEand VALUE in the Header Manager as Authorization and "Bearer xxxxyxyxyxz" respectively.
The request is running for 21 seconds each time and then its failed with below text
org.apache.http.conn.HttpHostConnectException: Connect to abcd.uat.xyz.com:443 [abcd.uat.xyz.com/11.222.250.10] failed: Connection timed out: connect.
Am I sending the bearer token in right way with Header Manager or is there some other way to send this kind of requests?
Note: Its(The same request and Bearer token) working perfectly in Postman and I am getting the correct response as well.
The issue is resolved after adding Proxy Server details to the request. I have added those in Advanced section of HTTP request.
In Postman, the tool using default system proxy settings, hence working without any issues but when it comes to Jmeter we need to add Proxy Server details explicitly.
Based on the exception it seems, you are trying to access HTTP server with HTTPS request.
Make sure to confirm whether "abcd.uat.xyz.com:443" support https or not..If not simply make your request HTTP by updating Protocol field.

What's wrong with this http request? Is there a validator somewhere?

I'm trying to send an http request but get 400 Bad Request from the server. How do I know what's wrong? Is there an http request validator somewhere on the web? If not, can somebody explain why this request fails:
GET http://www.example.com/index.htm HTTP/1.1
connection: close
content-length: 0
The request does end in \r\n\r\n.
I solved it: With http 1.1 the host header is required. When I added that header the request succeded and I received the expected response.

POST request with Content-Type application/x-www-form-urlencoded and

My requirement is very simple.
Call POST request with id and password.
Header has Content-Type = application/x-www-form-urlencoded
and data is also passed as urlencoded like below
Response is coming in xml format.
I tried a lot of examples from everywhere but nothing seems to be working. It gives me back 401 Unauthorized which is an error that target API throws if request is not in proper format.
http://zetcode.com/java/getpostrequest/
Exactly what I needed.
Java HTTP POST request with HttpURLConnection section on the page did the work.

JMeter http request works via fiddler but not without

I have a simple thread group with HTTP requests as below:
Do Login - POST request
grab the authorization bearer token
Get eventId - GET request
This is a simple HTTP GET request like this http://server_ip:8080/rest/v1/events/1234567
Pass the authorization bearer token in HTTP Header Manager
When I run the above, the Login post request goes through fine. I get a 200 OK and the response header ad message looks fine.
But the 'Get eventId' request fails and returns a 400 Bad Request.
However when I start JMeter to go through the proxy like below, the 'Get eventId' request returns a 200 OK and the response looks as expected.
jmeter.bat -H 127.0.0.1 -P 8888
I am not sure what I am doing wrong?
As per 400 Bad Request status code description:
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server could not understand the request due to invalid syntax.
Most likely you need to add HTTP Header Manager to send Content-Type header with the value of application/json (or whatever MIME type server expects).
If this is not the case - inspect what is being sent in both cases using View Results Tree listener and amend JMeter configuration so requests would look exactly the same (apart from dynamic token)

Mandrill API error for send request

I have a problem while sending a message via Jersey client on Mandrill API. I use Jersey client as follows:
ClientBuilder.newClient()
.register(JacksonJsonProvider.class)
.target(“https://mandrillapp.com/api/1.0/messages/send.json”)
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.json(methodEntity));
Below you can see logged headers, method and content of the API request.
POST https://mandrillapp.com/api/1.0/messages/send.json
Accept: application/json
Content-Type: application/json
{"message":{"subject":"Hello World!","text":"Really, Im just saying hi from Mandrill!","to":[{"email":"marcel#xxxx.com","name":"Marcel cccc","type":"to"}],"headers":{},"tags":["test"],"from_email":"info#xxxxx.com","auto_text":true,"preserve_recipients":false},"async":false,"key":"EWIBVEIOVBVOIEBWIOVEB"}
In response to this request I keep receiving following message:
[{"email":"marcel#XXXX.com","status":"rejected","_id":"0ea5e40fc2f3413ba85b765acdc5f17a","reject_reason":"invalid-sender"}]
I do not know what the issue may be, from some posts I figured out I must use UTF-8 to encode my message and headers. But setting encoding to UTF-8 did not do much good. Otherwise the payload seems fine to me and moreover I found on forums that invalid sender can mean any other kind of issue (not just invalid sender which is sad).
I had exactly same problem with
"reject_reason":"invalid-sender"
You probably check already similar question Mandrill “reject_reason”: “invalid-sender”
Try it if it helps. I realize that you also missing header parameter in your request
e.g. User-Agent: Mandrill-myclient/1.0
Please try also add this parameter to your Jersey Client setup as following:
ClientBuilder.newClient()
.register(JacksonJsonProvider.class)
.target(“https://mandrillapp.com/api/1.0/messages/send.json”)
.request(MediaType.APPLICATION_JSON_TYPE)
.header("User-Agent", "Mandrill-myclient/1.0")
.post(Entity.json(methodEntity));
Does it help?

Resources