首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VC++调用WebServer有关问题——不纯粹是散分100…O(∩_∩)O

2012-03-12 
VC++调用WebServer问题——不纯粹是散分100……O(∩_∩)O~这个帖子是专门给在VC++中如何获取天气预报温度信息并

VC++调用WebServer问题——不纯粹是散分100……O(∩_∩)O~
这个帖子是专门给在VC++中如何获取天气预报温度信息并保存为txt帖子中帮助我的朋友们加分的帖子。我的帖子最多只能悬赏100分,各位大虾,抱歉。O(∩_∩)O~

[解决办法]
真不会,UP
[解决办法]

C/C++ code
#include "stdafx.h"#include <iostream> #include <winsock.h> #include <string> #include <vector>#pragma comment(lib, "ws2_32.lib") using namespace std;wchar_t* Utf8ToUnicode(const char* buf){    int len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);    wchar_t *tmp = new wchar_t[len*2+1];    ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, tmp, len);        return tmp;}//string UnicodeToAnsi(const wchar_t* buf)//{//    int len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);//    if (len == 0) return "";////    std::vector<char> utf8(len);//    ::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);////    return &utf8[0];//}void main(){    struct hostent *pURL;    struct sockaddr_in addr;     WSADATA WSAData={0};     SOCKET sockfd;     string header;    static char text[BUFSIZ];    WSAStartup(MAKEWORD(2,2), &WSAData);    sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);     pURL = gethostbyname("www.webxml.com.cn");     addr.sin_family = AF_INET;     addr.sin_addr.s_addr = *((unsigned long*)pURL->h_addr);     addr.sin_port = htons(80);    connect(sockfd,(SOCKADDR *)&addr,sizeof(addr));    header="GET ";    header.append("/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=57073");    header.append(" HTTP/1.1\r\n");    header.append("HOST: ");    header.append("www.webxml.com.cn");    header.append("\r\nConnection: Close\r\n\r\n");    send(sockfd, header.c_str(), strlen(header.c_str()), 0);    int clen = 0;    wchar_t *tmp;    wstring s;    while (clen = recv(sockfd, text, BUFSIZ, 0) != NULL)     {         tmp = ::Utf8ToUnicode(text);        s.append(tmp);    }     cout<<s.c_str()<<endl;    closesocket(sockfd);     WSACleanup();     system("PAUSE");}
[解决办法]
lz啊 楼上的对你的问题涉及到的问题有点研究的

我是来up的 嘿嘿 。。。

热点排行