Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Wysłanie POST content type: application/xml
d.stp
post 27.01.2014, 18:50:26
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 19.04.2012

Ostrzeżenie: (0%)
-----


Muszę wysłać metodą POST (kontent type: application/xml) takie coś:

  1. <test>
  2. <a>test</a>
  3. <b>123</b>
  4. </test>


pod jakiś adres url, ale nie bardzo wiem jak to zrobić.

Ten post edytował d.stp 27.01.2014, 20:10:58
Go to the top of the page
+Quote Post
Wazniak96
post 27.01.2014, 20:05:02
Post #2





Grupa: Zarejestrowani
Postów: 550
Pomógł: 75
Dołączył: 5.06.2012
Skąd: Lębork

Ostrzeżenie: (0%)
-----


1. Nie kontent a content facepalmxd.gif
2. Poczytaj o curl.
Go to the top of the page
+Quote Post
d.stp
post 27.01.2014, 20:06:16
Post #3





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 19.04.2012

Ostrzeżenie: (0%)
-----


Tak miałem w dokumentacji... biggrin.gif biggrin.gif

A nie da się jakoś inaczej? Mój serwer nie obsługuje CURLa, a zmiana serwera raczej odpada ;/
Go to the top of the page
+Quote Post
vonski
post 27.01.2014, 20:30:16
Post #4





Grupa: Zarejestrowani
Postów: 292
Pomógł: 89
Dołączył: 27.12.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Możesz użyć file_get_contents w odpowiednim kontekście - stream_context_create. Do tego powinna przydać się jeszcze http_build_query.


--------------------
Zend Certified Engineer | Microsoft Certified Professional: Programming in HTML5 with JavaScript & CSS3 | Blog
Go to the top of the page
+Quote Post
d.stp
post 27.01.2014, 20:53:14
Post #5





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 19.04.2012

Ostrzeżenie: (0%)
-----


Jednak serwer obsługuje curla.

Mam takie coś:

  1. <?php
  2.  
  3. function post_xml($url, $xml) {
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_HEADER, 1);
  6. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  7. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  8. curl_setopt($ch, CURLOPT_URL, $url);
  9. curl_setopt($ch, CURLOPT_POST, 1);
  10. curl_setopt($ch, CURLOPT_POSTFIELDS, array('data' => $xml));
  11. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
  13.  
  14. $result = curl_exec($ch);
  15. $info = curl_getinfo($ch);
  16. curl_close($ch);
  17. return $result;
  18. }
  19.  
  20. $xml = '<?xml version="1.0" encoding="UTF-8"?><a><b>aaa</b></a>';
  21.  
  22. $url = "https:/url/x/x/x";
  23. $result = post_xml($url, $xml);
  24. echo "<pre>"; print_r($result); echo "</pre>";
  25.  
  26. ?>


Próbowałem też z:

  1. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));


I w obu przypadkach:

Kod
HTTP/1.1 100 Continue

HTTP/1.1 404 Not Found
Date: Mon, 27 Jan 2014 19:40:40 GMT
Server: Apache
Content-Length: 110
Connection: close
Content-Type: text/plain

Could not find resource for relative :


Link jest na pewno dobry :/

Dodam jeszcze, że w dokumentacji jest tak napisane:

Kod
Dostęp do API (interfejsu REST) jest chroniony za pomocą basic-authorization. Przy wywoływaniu
wszystkich metod, należy podać login i hasło Partnera.
W celu rejestracji, należy wysłać metodą POST (kontent type: application/xml)
następujący XML:
pod adres: https://xx/x/x/x/
W przypadku prawidłowej rejestracji (kod HTTP 2xx), zwrotnie zostanie dostarczony XML:


Ten post edytował d.stp 27.01.2014, 20:45:36
Go to the top of the page
+Quote Post
Wazniak96
post 27.01.2014, 22:21:21
Post #6





Grupa: Zarejestrowani
Postów: 550
Pomógł: 75
Dołączył: 5.06.2012
Skąd: Lębork

Ostrzeżenie: (0%)
-----


spróbuj tego wink.gif
  1.  
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4. curl_setopt($ch, CURLOPT_URL, $url);
  5. curl_setopt($ch, CURLOPT_USERPWD, "login:haslo");
  6. $result = curl_exec($ch);
  7. curl_close($ch);
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.06.2025 - 21:59