询问者
请问为何接收不到数据??急急!

常规讨论
-
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://upload.docin.com/uploaddoc");
req.Method = "post";
req.ContentType = "application/x-www-form-urlencoded";
FileStream fs = new FileStream(Server.MapPath("~/upload/属性的理解.doc"), System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] SomeBytes = Encoding.Default.GetBytes("Filedata=" + fs.Name + "&title=aaaa&desc=bbbb&pcatid=5&catid=6&userId=5163404_155198002&keyword=aaa");
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();
sr.Close();
res.Close();Response.Write(backstr);
}
}
XSINA他来了~
全部回复
-
有一高手用java实现了,可他不会用.net ,5555555555~~~
这是他写的代码:
public class TestUtil {
@SuppressWarnings("deprecation")
public static void main(String args[]){
try{
HttpClient hc = new HttpClient();
MultipartPostMethod method = new MultipartPostMethod("http://upload.docin.com/uploaddoc");
method.addParameter("Filedata", "dup.txt", new java.io.File("f://dup.txt"));
method.addParameter("title", "aaaa");
method.addParameter("desc", "bbbb");
method.addParameter("pcatid", "5");
method.addParameter("catid", "6");
method.addParameter("userId", "5163404_155198002");
method.addParameter("keyword", "aaa");
hc.executeMethod(method);
System.out.println(method.getResponseBodyAsString());
}catch(Exception ex){
ex.printStackTrace();
}}
}
XSINA他来了~