ページ 1 / 1
POST送信
Posted: 2010年4月14日(水) 13:24
by TKJ
char para[/url]="title=test&name=test&mail=a@docomo.ne.jp&comment=test&pass=1234&ses=&cookie=&upfile=&id=test&mode=thread";
/*省略*/
strcpy(buf,"POST /test/test.php HTTP/1.1\r\n");
strcat(buf,"Host: ");
strcat(buf,host);
strcat(buf,"\r\n");
strcat(buf,"Content-Length: ");
strcat(buf,(const char *)strlen(para));
strcat(buf,"r\n");
strcat(buf,"\r\n");
strcat(buf,para);
strcat(buf,"\r\n");
strcat(buf,"\r\n");
/*省略*/
ちゃんと送信できているか自作したPHPに送信したのですが
送信できていないみたいです。
どこか悪いところありますか?
Re:POST送信
Posted: 2010年4月14日(水) 22:21
by Justy
それだけだと、なかなか推測も難しいんでけど……。
Content-Typeはどこかで指定していますか?
Re:POST送信
Posted: 2010年4月14日(水) 22:49
by box
それはそうと、そんなにstrcatを連発させずとも、
sprintf一個でOKでは?
Re:POST送信
Posted: 2010年4月15日(木) 01:07
by TKJ
boxさんが助言してくださったので
sprintf(buf,"POST /bbs.aqbb.net/bbs.php?guid=ON HTTP/1.1\r\n"
"Host: %s\r\n"
"Content-Length: 96\r\n"
"Cookie: 0\r\n"
"User-Agent: MSIE7.0\r\n"
"REFERER:
http://www.yahoo.co.jp\n"
"Connection: close\r\n"
"\r\n"
"title=ABFA%s&name=ABFA&mail=&comment=ABFA&pass=&ses=%s&cookie=&upfile=&id=test&mode=thread\r\n"
"\r\n"
,host,ses,ses);
このように編集しました。
この後sendで送信し結果をrecvで受信してます。
send(s,buf,strlen(buf),0);
recN = recv(s,buf,sizeof(buf),0);
PHP側で
if($_POST["mode"] != 'thread')
{
echo'ERROR!!'
}
else
{
/*受信データを全表示*/
}
としています。
このとき正常にsendでPOST送信できていれば
recvのとき、「ERROR!!」は返ってこないはずなのですが
なぜか「ERROR!!」が返ってきます。
これはPOST送信できていないということ
だと思うのですが。。。
Re:POST送信
Posted: 2010年4月15日(木) 15:03
by TKJ
ちなみにrecvで受取った文字列はこうなります。
HTTP/1.1 200 OK
Date: Thu, 15 Apr 2010 05:53:20 GMT
Server: Apache
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html
300
<html lang="ja">
<head>
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"><link rel
="stylesheet" href="pc.css" type="text/css"><title>えらー</title>
</head>
<body text="black" bgcolor="white" alink="green" vlink="blue">
<table width="100%"><tr><td bgcolor="skyblue"><div align="center">[color=b
lack">えらー[/color]</div></td></tr>< /table>
ERROR!!
<center>-[url]admin[/url]-</center>
</body>
</html>
0
Re:POST送信
Posted: 2010年4月15日(木) 16:41
by ookami
Re:POST送信
Posted: 2010年4月16日(金) 04:29
by TKJ
ありがとうございます。
無事に送信することができましたが
どうしても納得のいかないことがあるので
教えてください。
パラメータを
sprintf(param,"title=%s&name=%s&comment=%s&ses=%s&id=test&mode=thread",title,name,comment,ses);
このようにしてchar型配列paramに格納しました。
POST送信するときはContent-Lengthで文字数を指定する必要があるので
strlen(param)
で文字数を取得しました。
sprintf(buf,"POST /bbs?guid=ON HTTP/1.1\r\n"
"REFERER:
http://bbs.aqbb.net/form/test?guid=ON\n"
"User-Agent: MSIE7.0\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Host: %s\r\n"
"Content-Length: %d\r\n"
"Cache-Control: no-cache\r\n"
"\r\n"
"%s\r\n"
"\r\n"
,host,strlen(eparam),eparam);
こんな感じです。
これで送信することができませんでした。
文字数というのは大文字と小文字で変わるのでしょうか?
例えば
aだったらContent-Lengthは1で
AだったらContent-Lengthは2
になるのですか?