Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> CURL DPD UK, API DPD UK
casperii
post 6.02.2018, 20:24:21
Post #1





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


Witam,
próbuje się połączyć z DPD UK i pobrać informację o przesyłce.
Mój kod:

  1. $url = "https://apps.geopostuk.com/trackingcore/ie/parcels";
  2. $xml = '<?xml version="1.0" encoding="UTF-8"?>
  3. <trackingrequest>
  4. <user>user</user>
  5. <password>password</password>
  6. <trackingnumbers>
  7. <trackingnumber>XXXX</trackingnumber>
  8. </trackingnumbers>
  9. </trackingrequest>
  10. </xml>';
  11.  
  12. $handle = 'output.xml';
  13. $handle = fopen($handle, 'w');
  14. fwrite($handle, $xml);
  15. $post_data['xml'] = $handle;
  16.  
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL, "".$url."" );
  19. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST" );
  20. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  21. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  23. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  24. "Content-Type: application/xml; charset=UTF-8",
  25. "Accept: application/xml; charset=UTF-8",
  26. "Authorization: Basic ". base64_encode("user:password") ."",
  27. "GEOClient: account/number",
  28. "trackingnumbers:XXXXX",
  29. "Content-Length: ".$handle.""
  30. ));
  31. $response = curl_exec($ch);
  32.  
  33. if (curl_errno($ch)) {
  34. print curl_error($ch);
  35. }
  36. curl_close($ch);
  37. $result = json_decode($response);
  38. echo var_dump($response);


Natomiast serwer zwraca mi: Client sent a bad request.
Gdyby jednak ktoś chciał zajrzeć w dokumentacje DPD UK:

Server: ftp.geopostuk.com
User: edidev
Password: acy7bies
Go to the top of the page
+Quote Post
nospor
post 7.02.2018, 10:54:49
Post #2





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Jesli API wymaga xml to wysylaj mu xml a nie lokalny uchwyt do pliku xml...

I jeszcze to:
"Content-Length: ".$handle.""

mamy takie powiedzenie: Piles, nie pisz kodu wink.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
casperii
post 7.02.2018, 16:29:23
Post #3





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


@nospor
co bym nie zrobił to albo otrzymuje błąd 415, albo w/w komunikat:
Client sent a bad request.
bool(true)


Próbuje walczyć dalej:

  1. $url = "https://apps.geopostuk.com/trackingcore/ie/parcels";
  2. $options = array(
  3. 'user' => "user",
  4. 'password' => "haslo",
  5. 'GEOClient' => "numer",
  6. 'trackingnumber' => "numer"
  7. );
  8.  
  9. $ch = curl_init();
  10. curl_setopt($ch, CURLOPT_URL, "".$url."" );
  11. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST" );
  12. curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
  13. //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  15. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  16. "Content-Type: application/xml",
  17. "Accept: application/xml",
  18. "Content-Length: 0"
  19. ));
  20. $response = curl_exec($ch);
  21.  
  22. if (curl_errno($ch)) {
  23. print curl_error($ch);
  24. }
  25. curl_close($ch);
  26. $result = json_decode($response);
  27. echo var_dump($response);


Czy mógłbyś mnie nakierować czy idę w dobrą stronę? facepalmxd.gif Ewentualnie czy jest możliwość by sprawdzić co jest wymagane do przesłania na serwer? Wiem wiem dokumentacja, tylko ta cała ich dokumentacja jest ohno-smiley.gif
Go to the top of the page
+Quote Post
nospor
post 7.02.2018, 16:41:14
Post #4





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Nie za bardzo wiem jak mam ci pomoc.

1) Nie podales nam zadnej dokumentacji i oczekujesz ze wywrozymi sobie jak ona wyglada? Bo chyba nie mowisz o tym dostepie do ftp gdzie jest od groma katalogow i plikow i my mamy w tym szukac?
2) Skoro masz wyslac xml to slij xml. W obu kodach co pokazales ani razu nie widze bys slal xml.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
casperii
post 7.02.2018, 17:51:47
Post #5





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


@nospor dokumentacja znajduje się tutaj:
Tracking API: Please see the DPD Group Tracking API.pdf document within the Integration documents\Tracking folders.

na wskazanym wyżej FTP.

Problemem jest tutaj fakt, że nie wiem w jaki sposób mam wysłać formatke XML , żeby w odpowiedzi uzyskać dane które mnie interesują.

Bo jeśli by to chodziło o jsona to by wyglądało coś w ten deseń:

  1. $options = array(
  2. 'http' => array(
  3. 'method' => 'POST',
  4. 'header'=> "Content-Type: application/json\r\n" .
  5. "Accept: application/json\r\n".
  6. "Authorization: Basic ". base64_encode("user:password") ."\r\n".
  7. "GEOClient: 4444\r\n".
  8. "Content-Length: 0"
  9. )
  10. );
  11.  
  12.  
  13. $context = stream_context_create($options);
  14. $result = file_get_contents($url, false, $context);
  15. $response = json_decode($result);
Go to the top of the page
+Quote Post
nospor
post 7.02.2018, 17:54:44
Post #6





Grupa: Moderatorzy
Postów: 36 441
Pomógł: 6290
Dołączył: 27.12.2004




Cytat
Bo jeśli by to chodziło o jsona to by wyglądało coś w ten deseń:


O, a to ciekawe... Mozesz mi wskazac, w tym kodzie co teraz wstawiles, miejsce w ktorym wysylasz tego JSON?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
casperii
post 7.02.2018, 18:24:10
Post #7





Grupa: Zarejestrowani
Postów: 680
Pomógł: 28
Dołączył: 14.08.2014

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


źle się wyraziłem, wysyłam postem, odbieram

  1. $response = json_decode($result);


co nie zmienia faktu, że nadal nie uzyskałem odpowiedzi jak wysyłać xmla:)
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.04.2024 - 08:37