HTTP Post Packet schicken klappt nicht
-
Guten Tag,
ich versuche ein POST Paket zu einer Webseite zu schicken:printf(buf,"POST index.html HTTP/1.1\r\nAccept: */*\r\nUser-Agent: TestBrowser\r\nHost: Host.de\r\nConnection: Keep-Alive\r\n\r\n");Aber als Antwort vom Server erhalte ich nur:
HTTP/1.0 411 Length Required\r\n
Dabei müsste ich normal etwas ganz anderes erhalten.
-
Das geht so:
POST /index.php HTTP/1.1 Host: site.com Content-Type: application/x-www-form-urlencoded Content-Length: 27 field1=value1&field2=value2
-
Warum Content-Length: 27?
-
"field1=value1&field2=value2" besteht aus 27 Zeichen

-
Klappt immer noch nicht:
sprintf(buf,"POST index.php HTTP/1.1\r\nAccept: */*\r\nUser-Agent: TestBrowser\r\nHost: www.google.de\r\nConnection: Keep-Alive\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: 0\r\n\r\n");Habe ich jetzt mals als Test probiert eigentlich müsste ich folgendes Paket als Antwort erhalten:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>405 Method Not Allowed</title>
<style><!--
body {font-family: arial,sans-serif}
div.nav {margin-top: 1ex}
div.nav A {font-size: 10pt; font-family: arial,sans-serif}
span.nav {font-size: 10pt; font-family: arial,sans-serif; font-weight: bold}
div.nav A,span.big {font-size: 12pt; color: #0000cc}
div.nav A {font-size: 10pt; color: black}
A.l:link {color: #6f6f6f}
A.u:link {color: green}
//--></style>
<script><!--
var rc=405;
//-->
</script>
</head>
<body text=#000000 bgcolor=#ffffff>
<table border=0 cellpadding=2 cellspacing=0 width=100%><tr><td rowspan=3 width=1% nowrap>
<b><font face=times color=#0039b6 size=10>G</font><font face=times color=#c41200 size=10>o</font><font face=times color=#f3c518 size=10>o</font><font face=times color=#0039b6 size=10>g</font><font face=times color=#30a72f size=10>l</font><font face=times color=#c41200 size=10>e</font> </b>
<td> </td></tr>
<tr><td bgcolor="#3366cc"><font face=arial,sans-serif color="#ffffff"><b>Error</b></td></tr>
<tr><td> </td></tr></table>
<blockquote>
<H1>Method Not Allowed</H1>
The request method <code>POST</code> is inappropriate for the URL <code>/</code>.<p>
</blockquote>
<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor="#3366cc"><img alt="" width=1 height=4></td></tr></table>[quote]
Aber ich bekomme diese Antwort nicht.
Auch wenn ich eine Seite nemme die richtig mit POST Parametern arbeitet klappt es nicht.
-
POST ohne Daten zu senden (zu "posten") ist auch irgendwie sinnlos

(www.google.de unterstützt POST!)Was bekommst Du denn stattdessen?
-
Erhalte vom Server dann:
HTTP/1.1 302 Found
Location: http://www.google.com/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Thu, 18 Feb 2010 17:46:43 GMT
Server: sffe
Content-Length: 219
X-XSS-Protection: 0<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
-
Nimm doch "GET"!?
-
1. Die Seite – www.google.de/index.php – existiert nicht.
2. wennschon, dann POST **/**index.php...
3. POST ohne POST-Daten - wie sinnlos
-
Ok habe es jetzt hinbekommen.
2. wennschon, dann POST /index.php...
Klappt auch bei POST index.php