问个问题啊 谁帮我看看啊 Content-Disposition: form-data; name="file1"; filename="C:\Documents and Settings\guomin\桌面\新建 文本文档.rar"
Content-Type: application/octet-streamRar! 蠍s
袻t 侱 牧t﹖E:3$ 新建 文本文档.txt ea苞^ 嚇,g嘽h. txt 遂蟅BQk涾548g濟纃>韑):綜H?{ @
-----------------------------7d9271272020e
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream上面这段数据 是在一个xml文件中的 ,我现在读取到一个变量里的时候 读到 Rar! 后面的就读不下去了
我是这样读的
char * temp = new char[1024*20] ;
ifstream fin;
fin.open((char*)(LPCTSTR(strFileName),ios::binary);
fin.read(temp,1024*20);二进制读取 读到 Rar! 这里 后面的全读不到了谁帮我看看啊
Content-Type: application/octet-streamRar! 蠍s
袻t 侱 牧t﹖E:3$ 新建 文本文档.txt ea苞^ 嚇,g嘽h. txt 遂蟅BQk涾548g濟纃>韑):綜H?{ @
-----------------------------7d9271272020e
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream上面这段数据 是在一个xml文件中的 ,我现在读取到一个变量里的时候 读到 Rar! 后面的就读不下去了
我是这样读的
char * temp = new char[1024*20] ;
ifstream fin;
fin.open((char*)(LPCTSTR(strFileName),ios::binary);
fin.read(temp,1024*20);二进制读取 读到 Rar! 这里 后面的全读不到了谁帮我看看啊
>>fin.open((char*)(LPCTSTR(strFileName) ); 不需要使用二进制方式读取
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, */*
Referer: http://cg3a26.mail.163.com/a/j/js3/index.jsp?sid=cAXHLMLLZqvXFTYqAELLdIamEYeobseL
Accept-Language: zh-cn
Content-Type: multipart/form-data; boundary=---------------------------7d9271272020e
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; TheWorld)
Host: cg3a26.mail.163.com
Content-Length: 520
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Province=0530; City=0531; ntes_mail_firstpage=normal; NTES_SESS=Z5mlNbd_Lt1t1yaAczwqIUOIDanYLubJZ5kNq8GGDxsClwr82lQrsyVQqSZJxQIDbf5S39QKkGQkQNh5QWQHRh8KYGPHoP4zH; S_INFO=1233815798|0; [email protected]|1233815798|0|mail163|11&19&1233815798915; Coremail=dfCyoVSZrISXI%cAXHLMLLZqvXFTYqAELLdIamEYeobseL; USERTRACK=123.232.114.66.1233815802434718; ntes_mail_truename=null; ntes_mail_province=null; ntes_mail_sex=null; mail_style=js3; [email protected]; wmsvr_domain=cg3a26.mail.163.com; MAIL163_SSN=guo_min2009; logType=-1; nts_mail_user=guo_min2009:-1:1-----------------------------7d9271272020e
Content-Disposition: form-data; name="file1"; filename="C:\Documents and Settings\guomin\桌面\新建 文本文档.rar"
Content-Type: application/octet-streamRar! 蠍s
袻t 侱 牧t﹖E:3$ 新建 文本文档.txt ea苞^ 嚇,g嘽h. txt 遂蟅BQk涾548g濟纃>韑):綜H?{ @
-----------------------------7d9271272020e
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream
-----------------------------7d9271272020e--
Content-Type: multipart/form-data; boundary=---------------------------7d9271272020e
-----------------------------7d9271272020e
Content-Disposition: form-data; name="file1"; filename="C:\Documents and Settings\guomin\桌面\新建 文本文档.rar"
Content-Type: application/octet-streamRar! 蠍s
袻t 侱 牧t﹖E:3$ 新建 文本文档.txt ea苞^ 嚇,g嘽h. txt 遂蟅BQk涾548g濟纃>韑):綜H?{ @
-----------------------------7d9271272020e
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream
事情不会总是那么理想的,如果你要在C/C++程序里处理XML怎么办呢?选择一:市面上的XML lib还是有几个的,最有名的当然是libxml。我一年前用过,很不错,我还特意写了一份简明教程,后来不知搁哪儿了。选择二:MS的MSXML,我要介绍的就是这个。先说一下在MSDN哪里找文档吧,往下看的时候也好有个参考:在Index里打:Windows Media Services 9 Series SDK=>Programming Reference=>Programming Reference (C++)=>XML DOM Interfaces (C++)。什么?Windows Media?呵呵,不错,我觉得这个guide反而是最清楚的,你直接找MSXML,得到的结果,我觉得还没这个好。在C程序里调用MSXML基本就是一堆COM接口,不过在Visual Studio里操作先要做点简单的设置:在你的Project里Add References=>COM标签=>Microsoft XML v4.0,5.0其实也有了,但因为是和Office一起发布的,觉得有点怪,不想用,反正也未必用什么很怪异的功能,4.0可以了。 然后在加入这两行:#include <msxml2.h>
#import <msxml4.dll>头文件和dll库。什么?在哪里加?头文件或者c/cpp文件啊,哪里合适放哪儿。然后就开始编程了,先定义两个必用的变量:IXMLDOMDocumentPtr xmlFile = NULL;
IXMLDOMElement* xmlRoot = NULL;为什么是必用的? 汗...第一步当然是初始化COM:if(FAILED(CoInitialize(NULL))) ....接下来初始化xmlFile对象:if(FAILED(xmlFile.CreateInstance("Msxml2.DOMDocument.4.0"))) ...然后就可以加载xml文件了:_variant_t varXml(L"C:\\test.xml"); //L for unicode
VARIANT_BOOL varOut;
xmlFile->load(varXml, &varOut);取得root element:xmlFile->get_documentElement(&xmlRoot))取得第一级element:IXMLDOMNodeList* xmlChildNodes = NULL;
xmlRoot->get_childNodes(&xmlChildNodes);遍历所有第一级element:IXMLDOMNode* currentNode = NULL;
while(!FAILED(xmlChildNodes->nextNode(¤tNode)) && currentNode != NULL)
{
//do something
}取得当前element的名称:BSTR nodeName;
currentNode->get_nodeName(&nodeName);取得当前element的一个attribute(假设这个attribute叫type)的值:IXMLDOMNamedNodeMap* attributes = NULL;
IXMLDOMNode* attributeName = NULL;
_bstr_t bstrAttributeName = "type";
BSTR nameVal;
currentNode->get_attributes(&attributes);
attributes->getNamedItem(bstrAttributeName, &attributeName);
attributeName->get_text(&nameVal);需要注意的是,你要记住释放所有的借口,IXMLDOM***->Release(),这可不是.NET,有人帮你GC,你得自己调用Release()来减reference count,it's COM, remember?好了,大致就这样,顺便提一下XPath:_bstr_t bstrXmlQuery = L"/books/book[@type=scifi and @author=fox]";
IXMLDOMNodeList* nodes = NULL;
if(FAILED(xmlRoot->selectNodes(bstrXmlQuery, &nodes)) || FAILED(nodes->get_length(&length)) || length == 0)
//no match found or something went wrong
else
//match found上面是找这样的node: <books>
<book type="scifi" author="fox">....
</book>
....
</books>具体的XPath语法就查手册吧,到处都有。哦,对了,忘了说:如果你全部用ATL的类的话,借口的调用会简单一点,不过很容易转换的,比如:IXMLDOMDocument* 对应 IXMLDOMDocumentPtr(我这里用了),其他基本也是加个Ptr,我不废话了。最后提供一个sample,我临时攒的。工作的时候写的程序当然不能拿来贴的,呵呵。这个sample基本就是遍历整个xml,然后报告一遍文件的结构,对每个node,如果它有一个叫id的attribute,就同时打印id的值。If you want the complete VS project, shoot me an email. But I guess no one really needs it anyway, right, : ) #include "stdafx.h"
#include <windows.h>
#include <msxml2.h>
#import <msxml4.dll>HANDLE logFile = NULL;#define INDENT 4#define TESTHR(hr) \
{ \
if(FAILED(hr)) goto fail; \
}void PrintChild(IXMLDOMNodeList* nodeList, int level)
{
if(nodeList == NULL)
return;IXMLDOMNode* currentNode = NULL;
IXMLDOMNodeList* childNodes = NULL;
IXMLDOMNamedNodeMap* attributes = NULL;
IXMLDOMNode* attributeID = NULL;while(!FAILED(nodeList->nextNode(¤tNode)) && currentNode != NULL)
{
BSTR nodeName;
TESTHR(currentNode->get_nodeName(&nodeName));
DWORD dwBytesWritten;
for(int i=0; i<level*INDENT; i++)
WriteFile(logFile, L" ", (DWORD)(sizeof(WCHAR)), &dwBytesWritten, NULL);//WCHAR msg[MAX_SIZE];
//wsprintf(msg, L"%s ", nodeName);
WriteFile(logFile, nodeName, (DWORD)(wcslen(nodeName)*sizeof(WCHAR)), &dwBytesWritten, NULL);TESTHR(currentNode->get_attributes(&attributes));
if(attributes!=NULL)
{
_bstr_t bstrAttributeName = "id";
BSTR idVal;
TESTHR(attributes->getNamedItem(bstrAttributeName, &attributeID));
if(attributeID != NULL)
{
TESTHR(attributeID->get_text(&idVal));
WriteFile(logFile, L" ", (DWORD)(sizeof(WCHAR)), &dwBytesWritten, NULL);
WriteFile(logFile, idVal, (DWORD)(wcslen(idVal)*sizeof(WCHAR)), &dwBytesWritten, NULL);
WriteFile(logFile, L"\r\n", (DWORD)(2*sizeof(WCHAR)), &dwBytesWritten, NULL);
attributeID->Release(); attributeID = NULL;
}
else
{
WriteFile(logFile, L"\r\n", (DWORD)(2*sizeof(WCHAR)), &dwBytesWritten, NULL);
}
attributes->Release(); attributes = NULL;}
else
{
WriteFile(logFile, L"\r\n", (DWORD)(2*sizeof(WCHAR)), &dwBytesWritten, NULL);
}TESTHR(currentNode->get_childNodes(&childNodes));
PrintChild(childNodes, level+1);
currentNode=NULL;
}fail:
if(childNodes!=NULL)
childNodes->Release();
if(attributeID!=NULL)
attributeID->Release();
if(attributes!=NULL)
attributes->Release();
if(currentNode != NULL)
currentNode->Release();
}int _tmain(int argc, _TCHAR* argv[])
{IXMLDOMDocumentPtr xmlFile = NULL;
IXMLDOMElement* xmlRoot = NULL;
_variant_t varXml(L"C:\\demo1.xml");logFile = CreateFile(L"log.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(logFile == INVALID_HANDLE_VALUE)
goto fail;TESTHR(CoInitialize(NULL));TESTHR(xmlFile.CreateInstance("Msxml2.DOMDocument.4.0"));VARIANT_BOOL varOut;
TESTHR(xmlFile->load(varXml, &varOut));TESTHR(xmlFile->get_documentElement(&xmlRoot));BSTR rootName;
DWORD dwBytesWritten;
TESTHR(xmlRoot->get_nodeName(&rootName));
WriteFile(logFile, rootName, (DWORD)(wcslen(rootName)*sizeof(WCHAR)), &dwBytesWritten, NULL);
WriteFile(logFile, L"\r\n", (DWORD)(2*sizeof(WCHAR)), &dwBytesWritten, NULL);IXMLDOMNodeList* xmlChildNodes = NULL;
TESTHR(xmlRoot->get_childNodes(&xmlChildNodes));PrintChild(xmlChildNodes, 2);fail:
if(logFile != INVALID_HANDLE_VALUE)
CloseHandle(logFile);
if(xmlChildNodes!=NULL)
xmlChildNodes->Release();
if(xmlRoot!=NULL)
xmlRoot->Release();
return 0;
}
MSXML::IXMLDOMDocumentPtr pCommandDoc;
pCommandDoc.CreateInstance(__uuidof(MSXML::DOMDocument));
pCommandDoc->put_async(VARIANT_FALSE);
pCommandDoc->put_validateOnParse(VARIANT_FALSE);
pCommandDoc->put_resolveExternals(VARIANT_FALSE);
pCommandDoc->put_preserveWhiteSpace(VARIANT_TRUE);
pCommandDoc->load(file.GetBuffer(0)); 2、在XML文档中查找指定的结点: //找到
MSXML::IXMLDOMNodePtr pRootNode=pCommandDoc->selectSingleNode("root/record");
if (pRootNode==NULL)
{
return ;
} 3、得到XML文档中,结点的属性 CString strTemp;
MSXML::IXMLDOMNamedNodeMapPtr pAttrs = NULL;
pRootNode->get_attributes(&pAttrs);
if (pAttrs==NULL)
{
return;
}
MSXML::IXMLDOMNodePtr pRequestTypeAttr=pAttrs->getQualifiedItem("name","");
_bstr_t strRequestType=pRequestTypeAttr->Gettext();
strTemp=strRequestType.operator char *(); 4、得到结点的内容 _bstr_t strVisiPort=pNode->Gettext(); 5、设置结点的内容 HRESULT hr=pNode->put_text(_bstr_t(m_strGatewayPassword));
6、设置一个属性内容
IXMLDOMAttribute *pa=NULL;
bstr = SysAllocString(L"属性1");
pXMLDom->createAttribute(bstr,&pNode);
var = VariantString(L"strin");
pa->put_value(var);
pRoot->setAttributeNode(pa, &pa1);
第二部分、如何使用SAX解析 概述:SAX使用的是加载式的,将会把XML文档分断,加载到内存中。使用事件通知的方式,来表示找到结点。好像没有写文档的能力吧。它的速度要比DOM快不少。 使用SAX的时候,就需要重载MSXML4.0中的一个接口ISAXContentHandler。 有几个函数重载了之后,当找到了结点之后,就会回调这一些函数。
http://support.microsoft.com/kb/246230
显示的话,根据xml头里的字符编码,转换成可显示的字符。
字符转换可以用MultiByteToWideChar和WideCharToMultiByte两个函数
ifstream fin;
fin.open((char*)(LPCTSTR(strFileName),ios::binary); 实际是读出来了如上所说计算长度=fin.read(temp,全部);
比对Content-Type: application/octet-stream
和Content-Disposition: form-data; name="file2"; filename=""计算位置char * temp = new char[1024*20] 定义另一个
memcpy 类存拷贝存档
fin.write...或者直接存档这个不像是xml 更像是拦截下来的数据流
这个数据是不能显示的
如果是定长的可以直接数出来不是固定的使用正则可能会出问题,不过可以试试上面描述的是个rar文件传输过程
============================================
那是因为你看不到而不是读不到,char*字符串以0为结尾,也就是Rar!后面紧跟着一个0,那么在调试或者输出的时候,Rar!后面的数据是不会显示出来了,因为你以字符串的方式进行输出。1、可以将temp改为wchar_t*
2、使用循环遍历temp,将0改为空格,之后再输出。
3、单独输出每一个char。