问题描述
在优酷的上传视频API中(WINFORM),要执行一系列的操作,前面已陆续测试成功,现在在一个叫“upload_slice”的API中需要传递二进制数据,他的API具体说明如下:upload_sliceInterfacePOSThttp://gX.upload.youku.com/gupload/upload_slice?<..parameters..><..BINARYDATA..>Parametersupload_token:string,MUSTprovide.slice_task_id:int,MUSTprovide.thesliceuploadtaskID.offset:int64,MUSTprovide.theoffsetinthesourcefile.length:int,MUSTprovide.thedatalength.crc:string,CRC32ofthedatasliceinhexstring.defaultisemptystring(””).hash:string,MD5ofthedatasliceinhexstring.defaultisemptystring(””).data:binary.Note:OneofCRCorHASHisrecommentedforerrortestingandslicere-uploading.ReturnValueerror:object.Onlyreturnedwhenerroroccured.code:int.type:string.description:string.slice_task_id:int,MUSTprovide.thenextsliceuploadtaskID.offset:int64,MUSTprovide.theoffsetofthenextsliceinthesourcefiletoupload.length:int,MUSTprovide.thedatalengthofthenextslicetoupload.transferred:int64.thedatalengththatalreadyuploaded.finished:boolen,whetherornotthefileistotallyuploaded.ErrorCodes120010205-Invaliduploadsessionid120010212-Internalerror:memoryerror120010218-CRCcheckerror120010219-Resourceunavailable120010221-Duplicatedoperation120010224-Badrequest120010225-HashcheckerrorSeeErrorDefinitionforfulllistoferrordefinitions.Sample(fordemoonly;layoutforeaseofreading)POST/gupload/upload_slice?upload_token=1a2b3c4d&slice_task_id=1328792850123&offset=12345678&length=12345&crc=dfc6f27bHost:g01.upload.youku.com<..BINARYDATA..>----201Created{"slice_task_id":1328793281567,"offset":12358023,"length":12345,"transferred":12358023,"finished":false}现在的问题是,如果把包含“文本”和二进制数据的内容一起POST到服务器?难道是把2部分分开再合并起来发送?如我下面的代码所示:///<summary>///合并数组///</summary>///<paramname="first"></param>///<paramname="second"></param>///<returns></returns>privatebyte[]mergerArray(byte[]first,byte[]second){byte[]result=newbyte[first.Length+second.Length];first.CopyTo(result,0);second.CopyTo(result,first.Length);returnresult;}privatevoidbtn_upload_slice_Click(objectsender,EventArgse){//upload_slicebyte[]data2=File.ReadAllBytes(file_name);Encodingencoding=Encoding.UTF8;uintcrc=my_CRC32.CalculateDigest(data2,(uint)0,length);//MessageBox.Show(crc.ToString());stringpostData="upload_token="+upload_token+"rn";postData+=("&slice_task_id="+slice_task_id+"rn");postData+=("&offset="+offset+"rn");postData+=("&length="+length+"rn");postData+=("&crc="+crc+"rn");//postData+=("&data="+"rn");//MessageBox.Show(postData);//postData+=File.ReadAllBytes(file_name)+"rn";byte[]data=encoding.GetBytes(postData);stringcontent=ZdSoft.Framework.Helper.HttpRequest.DoPostRequest("http://g"+gX+".up.youku.com/gupload/upload_slice",mergerArray(data,data2),1);//MessageBox.Show(content);btn_upload_slice.Enabled=false;}
其中,ZdSoft.Framework.Helper.HttpRequest.DoPostRequest是我自己的类,发送POST请求的,mergerArray是合并数组数据用的,但是服务器一直返回400,我要怎么解决?求高手指点!
解决方案
解决方案二:
是把参数弄成地址,再把二进制post过去!