<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Recent Posts in 400 bad request xml problem | Unfuddle Community</title>
    <link>http://unfuddle.com/community</link>
    <description>Unfuddle Community Forums</description>
    <item>
      <guid isPermaLink="false">www.unfuddle.com/community:6:772:2170</guid>
      <title>400 bad request xml problem replied by cr1000 @ Mon, 16 Nov 2009 10:11:12 UTC</title>
      <link>http://www.unfuddle.com/community/forums/6/topics/772</link>
      <description>Solved!
I moved '$config_headers[] = &quot;Content-length: &quot;.strlen($config_postbody)' to below where $config_postbody is being created. 
Duh.</description>
      <pubDate>Mon, 16 Nov 2009 10:11:12 UTC</pubDate>
      <author>cr1000</author>
    </item>
    <item>
      <guid isPermaLink="false">www.unfuddle.com/community:6:772:2169</guid>
      <title>400 bad request xml problem posted by cr1000 @ Mon, 16 Nov 2009 09:02:20 UTC</title>
      <link>http://www.unfuddle.com/community/forums/6/topics/772</link>
      <description>I've implemented the PHP ticket submission from http://unfuddle.com/community/forums/6/topics/151 and am getting a 400 Bad Request response:
&lt;pre&gt;
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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;errors&gt;
  &lt;error&gt;Priority can only be one of the following: 5, 4, 3, 2, 1&lt;/error&gt;
  &lt;error&gt;Summary can't be blank&lt;/error&gt;
&lt;/errors&gt;
&lt;/pre&gt;

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

&lt;pre&gt;
$priority = 3;
$config_method = 'POST';
$config_headers[] = &quot;MIME-Version: 1.0&quot;;
$config_headers[] = 'Accept: application/xml';
$config_headers[] = 'Content-type: application/xml';
$config_headers[] = &quot;Content-length: &quot;.strlen($config_postbody);
$config_headers[] = &quot;Cache-Control: no-cache&quot;;
$config_userpass = 'username:password'; // correct values used here, of course
$config_address = 'http://mydomain.unfuddle.com/api/v1/projects/1/tickets';
$config_postbody = &quot;&lt;ticket&gt;&lt;priority&gt;&quot;.$priority.&quot;&lt;/priority&gt;&lt;summary&gt;&quot;.XMLStrFormat('test subject').&quot;&lt;/summary&gt;&lt;description&gt;&quot;.XMLStrFormat(&quot;From: testuser@spam.com\n Issue: test issue&quot;).&quot;&lt;/description&gt;&lt;/ticket&gt;&quot;;
	
	
// 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);
&lt;/pre&gt;

Any ideas? The XML looks pretty straightforward to me.
Thanks.</description>
      <pubDate>Mon, 16 Nov 2009 09:02:20 UTC</pubDate>
      <author>cr1000</author>
    </item>
  </channel>
</rss>

