Forum Discussion

shabar's avatar
shabar
Contributor
11 years ago

[Resolved] Syntactical error in REST JSON

I am trying to run login REST service in SoapUIPro with jason.

But I a getting following syntactical error.

It's working fine when I switch to xml

Request

POST http://122.122.232.112/services/public/login HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
Accept: application/json
Content-Length: 115
Host: 122.122.232.112
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

{
"com.abc.dmb.cons.model.LoginInfo": {
"userId": "cons31312061521360",
"password": "Arif#1212"
}
}


Response


HTTP/1.1 400 Bad Request
Date: Fri, 06 Dec 2013 05:02:59 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Accept-Ranges: bytes
Server: abcd.setup.com.au
Content-Type: application/json;charset=ISO-8859-1
Transfer-Encoding: chunked
Connection: close

{"errorCode":"400","errorDescription":"The request sent by the client was syntactically incorrect."}



Please clarify


Cheers

8 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    The 400 response is coming for the web service, not SoapUI. So you will need to look at the raw request and compare it with one that works. You can also looks at HTTP traffic in "HTTP Log" tab at the bottom. But you will need some info from the party that provides the REST web service so you could see what request is been expected.

    Thanks,
    Michael Giller
    SmartBear Software
    • bhavikkp's avatar
      bhavikkp
      Occasional Contributor

      I have the same problem with my Rest Service.

       

      here is My Detailed Problem 

      I am getting response as " BAD REQUEST" 400.

       

      If I run that in my Ready API Toll but if same request I run from my friend system that its working as expected. 

      Is there a Problem with ReadyAPI 2.1.0 version.

       

      Its really Frustrationg when you have such problem and it was working from long time nothing that I have change in my tool nor in the Service or Environment .

      • groovyguy's avatar
        groovyguy
        Champion Level 1

        bhavikkp: You are replying to a thread that is almost 4 years old. Please start a new thread with your own specifics, as replying to this one obfuscates the issue and may not be seen in a timely manner for you to receive assistance. 

  • Thanks for your reply.

    I just tried the following publicly available web service. Even there XML request working fine but NOT the json one as below

    XML Request


    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:web="http://www.webserviceX.NET/">
    <soap:Header/>
    <soap:Body>
    <web:ConversionRate>
    <web:FromCurrency>USD</web:FromCurrency>
    <web:ToCurrency>AUD</web:ToCurrency>
    </web:ConversionRate>
    </soap:Body>
    </soap:Envelope>


    Response

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <ConversionRateResponse xmlns="http://www.webserviceX.NET/">
    <ConversionRateResult>1.0987</ConversionRateResult>
    </ConversionRateResponse>
    </soap:Body>
    </soap:Envelope>



    Json Request


    {
    "soap:Envelope": {
    "-xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
    "-xmlns:web": "http://www.webserviceX.NET/",
    "soap:Body": {
    "web:ConversionRate": {
    "web:FromCurrency": "USD",
    "web:ToCurrency": "AUD"
    }
    }
    }
    }


    Jason Raw Request


    POST http://www.webservicex.com/CurrencyConvertor.asmx HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: application/soap+xml;charset=UTF-8;action="http://www.webserviceX.NET/ConversionRate"
    Content-Length: 269
    Host: www.webservicex.com
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

    {
    "soap:Envelope": {
    "-xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
    "-xmlns:web": "http://www.webserviceX.NET/",
    "soap:Body": {
    "web:ConversionRate": {
    "web:FromCurrency": "USD",
    "web:ToCurrency": "AUD"
    }
    }
    }
    }



    Raw Response



    HTTP/1.1 400 Bad Request
    Cache-Control: private
    Transfer-Encoding: chunked
    Content-Type: text/html
    Server: Microsoft-IIS/7.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Fri, 06 Dec 2013 23:55:54 GMT

    Bad Request



    After checking "http logs" couldn't find anything suspicious.

    Can the service define as ONLY expect xml request?
  • Hi,

    The currency converter web service is a SOAP service and not a REST service. It does not interact with JSON.
  • Thanks for your reply

    So that means when you get this type of response, we basically we should check with the service first before make a decision regarding the request.

    Is there a way to identify these types of issue by examine the logs?


    Cheers
  • Hi,

    So that means when you get this type of response, we basically we should check with the service first before make a decision regarding the request.


    Yes, you should know ahead of time if the service expects xml, json, or can handle both.

    Is there a way to identify these types of issue by examine the logs?


    You will have to look at the error messages you receive and make that determination.
    Also review the documentation for your web services.