R
R
Rom Black2012-09-03 14:20:27
PHP
Rom Black, 2012-09-03 14:20:27

How to make post request xml?

I tried to write it myself, but apparently I misunderstood something.

there is an xml request like

<ApiRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <ApiKey>xxxxxxxxxxxxx</ApiKey>
  <Data xsi:type="Subscriber">
 <Mode>mode</Mode>
 <Force>false</Force>
 <ListId>1</ListId>
 <Email>[email protected]</Email>
 <Firstname>testName</Firstname>
  </Data>
</ApiRequest>


And the xml request handler is mysite.com/api/ You

should perform a POST request to add a new subscriber from xml and display the result (response xml).
How to implement it? curl?
I read the topics on the subject, but, apparently, I did not understand everything. Can you explain with my example?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
max_rip, 2012-09-03
@MrBlack

POST cannot be unnamed, there must be a field in which the data will be transferred, in your case it is xml. The essence is not entirely clear, you need to decide on which side of the server or client api?

S
s0rr0w, 2012-09-03
@s0rr0w

It is allowed to send "unnamed" data in POST. The files are transferred somehow :)
stackoverflow.com/questions/871431/raw-post-using-curl-in-php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,            "http://url/url/url" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST,           1 );
curl_setopt($ch, CURLOPT_POSTFIELDS,     "body goes here" ); 
curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain')); 

$result=curl_exec ($ch);

U
Urvin, 2012-09-03
@Urvin

cUrl has the ability to send POST requests.
Just to get started, you need to know the name of the field in order to insert the XML content there.

V
Vladimir Chernyshev, 2012-09-03
@VolCh

Check with who provides the API. I met various options, some expect that application / x-www-form-urlencoded will come, others that multipart / form-data, others that application / xml or text / xml, and someone can invent something of their own like application/mysite+xml.

S
Sergey, 2012-09-03
@seriyPS

Do not listen to those who say that the field in POST cannot be unnamed. It is not true.

$body_text = '<ApiRequest xmlns:xsi="ht'
...
curl_setopt($ch, CURLOPT_POSTFIELDS,     $body_text); 

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question