Search

400 bad request xml problem

Subscribe to 400 bad request xml problem 2 post(s)

 
cr1000

I’ve implemented the PHP ticket submission from http://unfuddle.com/community/forums/6/topics/151 and am getting a 400 Bad Request response:


HTTP/1.1 400 Bad Request
Date: Mon, 16 Nov 2009 09:01:16 GMT
Server: Apache
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.1.2
Cache-Control: no-cache
Set-Cookie: _unfuddle_session=98db536ebfe9d3256a58a9865ca2f42c; domain=.unfuddle.com; path=/; expires=Mon, 16 Nov 2009 11:01:16 GMT; HttpOnly
Content-Length: 172
Status: 400
Vary: Accept-Encoding,User-Agent
Connection: close
Content-Type: application/xml; charset=utf-8

<?xml version=“1.0” encoding=“UTF-8”??>Priority can only be one of the following: 5, 4, 3, 2, 1Summary can’t be blank

The php code looks like this (with XMLStrFormat() not included here, but it’s working fine):

$priority = 3;
$config_method = 'POST';
$config_headers[] = "MIME-Version: 1.0";
$config_headers[] = 'Accept: application/xml';
$config_headers[] = 'Content-type: application/xml';
$config_headers[] = "Content-length: ".strlen($config_postbody);
$config_headers[] = "Cache-Control: no-cache";
$config_userpass = 'username:password'; // correct values used here, of course
$config_address = 'http://mydomain.unfuddle.com/api/v1/projects/1/tickets';
$config_postbody = "".$priority."".XMLStrFormat('test subject')."".XMLStrFormat("From: testuser@spam.com\n Issue: test issue")."";
	
	
// Here we set up CURL to grab the data from Unfuddle

$chandle = curl_init();
curl_setopt($chandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chandle, CURLOPT_URL, $config_address);
curl_setopt($chandle, CURLOPT_HEADER, true);
curl_setopt($chandle, CURLOPT_HTTPHEADER, $config_headers);
curl_setopt($chandle, CURLOPT_USERPWD, $config_userpass);
curl_setopt($chandle, CURLOPT_CUSTOMREQUEST, $config_method);
curl_setopt($chandle, CURLOPT_POSTFIELDS, $config_postbody);
$output = curl_exec($chandle);
curl_close($chandle);

Any ideas? The XML looks pretty straightforward to me.
Thanks.

 
cr1000

Solved!
I moved ‘$config_headers[] = "Content-length: ".strlen($config_postbody)’ to below where $config_postbody is being created.
Duh.