Eddiu Posted December 2, 2010 Share Posted December 2, 2010 I'm trying to send a HTTPS POST request with XML data to a server using PHP. Anything sends to the server requires authentication therefore I'll use cURL. Some background info.: the XML data is to request the server to upload a file from a specific URL to its local storage. One rule of using this API is I MUST set the content type for each request to application/xml. This is what I've done but isn't working... <?php $fields = array( 'data'=>'<n1:asset xmlns:n1="http://.....com/"><title>AAAA</title><fileName>http://192.168.11.30:8080/xxx.html</fileName><description>AAAA_desc</description><fileType>HTML</fileType></n1:asset>' ); $fields_string = ""; foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); $url = "https://192.168.11.41:8443/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, "admin:12345678"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml', 'Content-length: '. strlen($fields_string)) ); $result = curl_exec( $ch ); curl_close($ch); echo $result; ?> I am expected to get an XML reply of either upload successful or upload failed. But instead I am getting this error message. HTTP/1.1 415 Unsupported Media Type Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=UTF-8 Content-Length: 0 Date: Thu, 02 Dec 2010 03:02:33 GMT I'm sure the file type is correct, the XML format is correct. I've tried urlencode the fields but it didn't work. What else I might have done wrong? Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted December 2, 2010 Share Posted December 2, 2010 try to urlencode the entire xml string like so: foreach($fields as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; } Quote Link to comment Share on other sites More sharing options...
Eddiu Posted December 2, 2010 Author Share Posted December 2, 2010 Tried that, didn't work. try to urlencode the entire xml string like so: foreach($fields as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; } Quote Link to comment Share on other sites More sharing options...
Eddiu Posted December 3, 2010 Author Share Posted December 3, 2010 anyone know the solution/work-around to this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.