c++中如何进行HTTP编程,发送一个XML文件给服务器?

xiaoma0401 2007-01-10 11:06:04
已经用socket建立一个连接,并可以向服务器端发送http请求

可是如何发送一个xml文件给对方呢

有知道的多帮忙了
...全文
891 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoma0401 2007-01-11
  • 打赏
  • 举报
回复
上面是代码

可是还是无法发出xml数据


高手指点阿


急急急急
xiaoma0401 2007-01-11
  • 打赏
  • 举报
回复
#pragma comment (lib, "wsock32.lib")
#include <string>
#include <winsock.h>
using namespace std;

void LogFile(char *p);
char fname[256];

int main(int arg, char* argv[])
{
WSADATA ws;
SOCKET s;
struct sockaddr_in addr;

int iResult;
long lResult;
char strSubAddr[1024], strBuffer[1024];

lResult = WSAStartup(0x0101,&ws);
s = socket(AF_INET,SOCK_STREAM,0);

addr.sin_family = AF_INET;
addr.sin_port = htons(8080);
addr.sin_addr.s_addr = inet_addr
("192.168.0.95");
iResult=connect(s,(struct sockaddr *)
&addr, sizeof(addr));
if(SOCKET_ERROR == iResult)
{
// connect fail
WSACleanup();
printf("%s","connect fail");
return FALSE;
}
else
{
// connect success
strcpy(strSubAddr, "POST /USBServer/server \r\n");
strcat(strSubAddr, "CONTENT-LENGTH: 10 \r\n");
strcat(strSubAddr, "Content-Type: text/xml \r\n");
strcat(strSubAddr, "<configuration>0</configuration> \r\n\r\n");
// strcat(strSubAddr, "Accept: */*\r\n");
// strcat(strSubAddr, "Accept-Language: ja\r\n");
// strcat(strSubAddr, "Accept-Encoding: gzip, deflate\r\n");
// strcat(strSubAddr, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n");
// strcat(strSubAddr, "Host: 192.168.0.95:8080\r\n");
// strcat(strSubAddr, "Connection: Keep-Alive \r\n\r\n");

//////////////////////////////////////////////////////////////////////////
strcpy(fname, "index.htm");
iResult = send(s, strSubAddr,strlen(strSubAddr),0);

// download file
do
{
strset(strBuffer,' ');
iResult = recv(s,strBuffer,sizeof(strBuffer),0);
LogFile(strBuffer);
} while( iResult !=0 );
}

WSACleanup();
return 1;
}

void LogFile(char *p)
{
FILE *fp=fopen(fname,"a+");
fprintf(fp,"%s\n",p);
fclose(fp);
}
xiaoma0401 2007-01-11
  • 打赏
  • 举报
回复
????


好像明白點

继续

http我看了,不过也没有讲怎么发送xml的阿

zhousqy 2007-01-10
  • 打赏
  • 举报
回复
xml格式的數據不就是文本么,儅字符串一樣發好了
zzw_happy 2007-01-10
  • 打赏
  • 举报
回复
下策:按http协议把文件读取出来直接发送到socket里。

一般来说web service应该用其它库的,axis好像有c++的版本,
还有一个gsoap库。lz可以去找找。
xiaoma0401 2007-01-10
  • 打赏
  • 举报
回复
鄙视wcpjavastudy()


没这么干的,凑什么热闹啊

不会自己开个帖子阿
xiaoma0401 2007-01-10
  • 打赏
  • 举报
回复
楼上的,昨天分数给了

谢谢

发送xml格式的数据就可以

应该怎么做??
zhousqy 2007-01-10
  • 打赏
  • 举报
回复
把文件讀出來作爲字符流發送行不?
smartwind 2007-01-10
  • 打赏
  • 举报
回复
char buf[2048] = "POST /test/xxx HTTP/1.1\nVia: 1.1 PROXY-TMP05\nContent-Length: length\nContent-Type: text/xml; charset=utf-8\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.573)\nHost: www.test.com.cn\nConnection: Keep-Alive\n\n<?xml ...";
与服务器的http端口建立socket连接,发送缓冲区内容
qingcairousi 2007-01-10
  • 打赏
  • 举报
回复
先找HTTP的spec来看看吧……
bingdian37 2007-01-10
  • 打赏
  • 举报
回复
先学http啦......
xiaoma0401 2007-01-10
  • 打赏
  • 举报
回复
有完整点的吗??


别老说概念
我不知道应该怎么发

对http根本就不了解
mLee79 2007-01-10
  • 打赏
  • 举报
回复
直接酱紫不行么 ....
POST /test HTTP/1.0
HOST: www.test.com
CONTENT-LENGTH: 10

<xml-doc/>
xiaoma0401 2007-01-10
  • 打赏
  • 举报
回复
zhousqy(标准C匪徒)(甩拉,甩拉)

能不能给个代码

64,644

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧