Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> POST przez protokół https, Jak wysłać dane metodą POST do https?
chfast
post
Post #1





Grupa: Zarejestrowani
Postów: 222
Pomógł: 0
Dołączył: 3.04.2003
Skąd: Wrocław

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


Chcę wysłać dane za pomocą nagłówka HTTP metodą POST do pewnego serwera, z którym muszę komunikować się za pomocą protokołu https.

Próbowałem wykorzystać do tego parametr $context w fopen" title="Zobacz w manualu php" target="_manual, ale otrzymuję z serwera błąd 400: Bad request.
  1. <?php
  2.  
  3. $request = "dane=1";
  4.  
  5. $header = "Host: server.netrn";
  6. $header .= "Content-Type: application/x-www-form-urlencodedrn";
  7. $header .= "Content-Length: ".strlen($request)."rn";
  8. $header .= "Connection: closern";
  9.  
  10. $opts['http']['method'] = "POST";
  11. $opts['http']['header'] = $header;
  12. $opts['http']['content'] = $request;
  13.  
  14. $context = stream_context_create( $opts );
  15. fopen( "https://server.net/index.php", false, $context );
  16.  
  17. ?>

Kod
HTTP request failed! HTTP/1.1 400 Bad Request


Próbowałem też wysłać podobny nagłówek za pomocą fsockopen" title="Zobacz w manualu php" target="_manual, ale efekt jest taki sam.
Go to the top of the page
+Quote Post
bela
post
Post #2


Administrator PHPedia.pl


Grupa: Developerzy
Postów: 1 102
Pomógł: 2
Dołączył: 14.09.2003

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


http://pl2.php.net/stream przykład 2
Go to the top of the page
+Quote Post
hwao
post
Post #3


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




http://hwao.be/code/http/

  1. <?php
  2. $httpRequest = new httpRequest( 'http://www.php.net/index.php' );
  3. // $httpRequest->proxy( '10.1.1.1', 80 ); // opcjonalne
  4. $httpRequest->cookie( array( 'nazwa' => 'value' ) ); // dane cookie
  5. $httpRequest->post( array( 'hwao' => array( 'lol', 'ek' ) ) ); // dane post
  6. $httpRequest->get( array( 'icos' => 'nono' ) ); // dane get
  7.  
  8. $httpResponse = new httpResponse( $httpRequest->send() );
  9. $cookie = $httpResponse->getCookie(); // ciastka wyslane przez serwer
  10.  
  11. echo '<pre>';
  12. print_r( $cookie );
  13. echo '<hr />';
  14. print_r( $httpResponse->getHeader() );
  15. echo '</pre><hr />';
  16. echo $httpResponse->getDocument(); 
  17. ?>
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 17:38