用header送出post表單

看板PHP作者 (Sissy's mate)時間17年前 (2009/02/11 22:32), 編輯推噓2(205)
留言7則, 3人參與, 最新討論串1/3 (看更多)
我想從AT&T的web TTS系統取得wav檔案, (對方的cgi會回應一個wav檔案) 這是錯誤訊息: HTTP/1.1 400 Bad Request Date: Wed, 11 Feb 2009 17:03:09 GMT Server: Apache/2.0.52 (CentOS) Content-Length: 326 Connection: close Content-Type: text/html; charset=iso-8859-1 Bad Request Your browser sent a request that this server could not understand. Apache/2.0.52 (CentOS) Server at 192.20.225.55/tts/cgi-bin/nph-talk Port 80 我修正程式了,紅字的部份 $fp = fsockopen("192.20.225.55" ,80, $errno, $errstr); if (!$fp){ echo "----->".$errstr."<-----"; die("$errstr ($errno)\n"); }else{ $data = "txt=".$_GET['txt']; $out="POST / HTTP/1.0\r\n"; $out.="Host: 192.20.225.55/tts/cgi-bin/nph-talk\r\n"; $out.="Content-type: application/x-www-post\r\n"; $out.="Content-length: " . strlen($data) . "\r\n"; $out.="Accept: */*\r\n"; $out.="\r\n".$data."\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.68.92.156

02/11 23:34, , 1F
會不會太硬, 這裡不能用 curl 嗎?
02/11 23:34, 1F

02/12 00:07, , 2F
有出現任何錯誤訊息嗎?
02/12 00:07, 2F

02/12 00:22, , 3F
fsockopen不用網址吧 給ip就好 網只是寫在POST後面
02/12 00:22, 3F

02/12 00:23, , 4F
Host裡面要寫http:// 吧? 不確定
02/12 00:23, 4F

02/12 00:25, , 5F
跟cgi什麼的完全沒有關係 還不都是HTTP
02/12 00:25, 5F

02/12 00:27, , 6F
另外curl的確比較好用
02/12 00:27, 6F

02/12 00:35, , 7F
fsockopen跟HTTP是不同層的東西
02/12 00:35, 7F
※ 編輯: costbook 來自: 203.68.92.156 (02/12 01:07)
文章代碼(AID): #19ak5ZZs (PHP)
文章代碼(AID): #19ak5ZZs (PHP)