0

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.

muchHassle
  • 21
  • 3
  • "java.lang.NumberFormatException: For input string" this error could be thrown when java trying to parse a string that contains alphabatic charachters – Basil Battikhi Nov 08 '18 at 16:29

1 Answers1

0

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
Ashish Yadav
  • 1,901
  • 2
  • 17
  • 23