简体   繁体   中英

PHP; get post string from external url (JAVA)

I need to send string data to an external url which is an API for clients, but I always get the server sending back an error, and then I checked the log in the server which is written in JAVA, it throws an exception

"java.lang.NumberFormatException: For input string: "{"success":false,"errorCode":"500","message":"Unknown Error!","value":null,"totalPageCount":0,"footerValue":null}"

and here's my piece of php code:

$context = stream_context_create(array( 
'http' => array( 
    'method' => 'POST', 
    'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
    'content' => $params  
    ), 
)); 
$received = file_get_contents(URL, false, $context); 
echo $received.'<br>';

I'm pretty sure the data I send to the server is in correct format as I have the access to the log, and I know that all response parameters from the server are in JSON, UTF-8 and post method, is there something I missed?

If more information needed please let me know, thanks.

You need to parse the string. You are getting NumberFormatException and this is because your server is receiving data which is not a numeric.

Integer.parseInt() // in java

You can parse the content in server side this way or send numeric data.

Another method:

Integer.valueOf() // in java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM