Guzzle Post with arrays and strings

1,252 views
Skip to first unread message

jj

unread,
Jul 23, 2013, 11:46:18 AM7/23/13
to guz...@googlegroups.com
When doing a Guzzle Post, If I pass a string the request, the response comes back correctly yet when I use a nested array it does not (I just get a 500 internal server error).

A shorthand version of what I am doing:


$client = new Guzzle\Http\Client();


$request = $client->post('http://foo.com',
	array(
		'Content-Type' => 'application/x-www-form-urlencoded',
		'Content-Length' => 'length'
	),array(
	'foo'=>'bar',
	'Data' => array(
		'LD'=> array(
			'ld1'=>1
		),
		'PD'=>array(
			'pd1'=>Input::get('pd1'),
			'pd2'=> Input::get('pd2'),
			'pd3'=>Input::get('pd3')
		),
		'CD'=>array(
			'cd1'=>Input::get('cd1'),
			'cd2'=>Input::get('cd2'),
			'cd3'=>Input::get('cd3')
	)
	));


When passing a string instead of an array to Data e.g:

<LD>
  <ld1>qwerty</ld1>
</LD>

<PD>
  <pd1>qwerty</pd1>
  <pd2>qwerty</pd2>
  <pd3>qwerty</pd3>
</PD>
<CD>
  <cd1>qwerty</cd1>
  <cd2>qwerty</cd2>
  <cd3>qwerty</cd3>
</CD>

The request works fine and returns the XML as expected.

I have no idea what i'm doing wrong. Hopefully someone with more experience can help. 

Michael Dowling

unread,
Jul 23, 2013, 12:05:10 PM7/23/13
to guz...@googlegroups.com
The first request is sending POST data in the body, while the second is sending XML date. They are completely different requests and I'm not surprised that they get different results .

Thanks,
Michael
--
You received this message because you are subscribed to the Google Groups "Guzzle - PHP HTTP client and REST client framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guzzle+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jj

unread,
Jul 23, 2013, 12:13:09 PM7/23/13
to guz...@googlegroups.com
Thanks for your reply. 

Is it possible to pass a set of array key pairs so that Guzzle builds up the XML? I can't see anything in the docs about it but it would just be so much cleaner, rather than building up the string.

Any advise appreciated, thanks.

Michael

unread,
Jul 26, 2013, 12:03:02 PM7/26/13
to guz...@googlegroups.com
This is what Guzzle's service descriptions can be used for. They can marshal arrays to XML and XML to arrays.

Reply all
Reply to author
Forward
0 new messages