Jump to content

Recommended Posts

Hi,

I am trying to logon to API using the java code and check the HTTP response. This is the first time I am trying. But, I am getting the below response.

{"HttpStatus":400,"ErrorMessage":"The request content-type is not supported","ErrorCode":4005}

Attached the java code that I am using. 

Could you please help me get through this?

 

LogonAPI.txt

Share this post


Link to post

Hi,

Based on the error message, we're working on the basis that the request is sent with an unacceptable Content-Type. Do you use Fiddler or some other tool to view the HTTP request that is being sent?

I used Postman to POST a succesful login request and with Fiddler I can view the Headers and the Raw request that was sent - see attached image. If you can screenshot your request we can then compare and see where the culprit is in your request that is leading to the error message.  

Many thanks!

image.png

 

Share this post


Link to post

Hi Dhiraj,

We need to see what the Java code is sending in the http headers and payload in order to determine where the unacceptable content type error is coming from. You can use the free tools Wireshark or Fiddler as you prefer, to capture the requests your code is sending - in the same way as shown in the screenshots previously. 

Kind Regards, PM

Share this post


Link to post

Hi Physicsman,

Apologies for the delay in responding you. The Java code is sending the below logon credential info and the headers info

        nameValuePairs.add(new BasicNameValuePair("Password", "XXXXXXX"));
        nameValuePairs.add(new BasicNameValuePair("AppVersion", "1"));
        nameValuePairs.add(new BasicNameValuePair("AppComments", ""));
        nameValuePairs.add(new BasicNameValuePair("UserName", "XXXXXXX"));
        nameValuePairs.add(new BasicNameValuePair("AppKey", "XXXXXXXX"));

        HttpPost httppost = new HttpPost("https://ciapi.cityindex.com/TradingAPI/session");
        httppost.setHeader("target", "session");
        httppost.setHeader("uriTemplate", "/");
        httppost.setHeader("transport", "POST");
        httppost.setHeader("envelope", "JSON");
        httppost.setHeader("contentType", "application/json");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));

Also, attached the screenshot of the output from Fiddler tool

HttpError-400.jpg

Share this post


Link to post

Hi,

It looks as though you are sending all the Service Info in the header of your call and that is likely the culprit to the 400 error response you are seeing. 

Please try sending just the Content-Type applicatoin/json in the header and keep your body the same and see if that works. Is your account a Live account or a demo/test account? If it is a demo/test account and you still have the problem, please send the demo account credentials to me via PM. I can make some test calls with that demo account to troubleshoot.

Kind Regards, PM

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×