Java getInputStream 400 errors

Posted by Bill Szerdy on Stack Overflow See other posts from Stack Overflow or by Bill Szerdy
Published on 2010-06-14T14:50:45Z Indexed on 2010/06/14 14:52 UTC
Read the original article Hit count: 276

Filed under:

When I contact a web service using a Java HttpUrlConnection it just returns a 400 Bad Request (IOException). How do I get the XML information that the server is returning; it does not appear to be in the getErrorStream of the connection nor is it in any of the exception information.

When I run the following PHP code against a web service:

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.myclientaddress.com/here/" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST,1 );
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=ted&password=scheckler&type=consumer&id=123456789&zip=12345");

$result=curl_exec ($ch);
echo $result;
?>

it returns the following:

<?xml version="1.0" encoding="utf-8"?>
<response>
    <status>failure</status>
    <errors>
        <error name="RES_ZIP">Zip code is not valid.</error>
        <error name="ZIP">Invalid zip code for residence address.</error>
    </errors>
</response>

so I know the information exists

© Stack Overflow or respective owner

Related posts about java