string postData = "access_token=" + access_token;                    
postData += "&status=" + Server.UrlEncode(GetWeather());
postData += "&pic=";FileStream file = new FileStream("C:\\Documents and Settings\\zhengw.BAUERHOME\\桌面\\weather.png", FileMode.Open, FileAccess.Read);
BinaryReader read = new BinaryReader(file);
int count = (int)file.Length;
                    byte[] buffer = new byte[count];
                    read.Read(buffer, 0, buffer.Length);
                    string msg = Encoding.UTF8.GetString(buffer);
                    data = encoding.GetBytes(postData+msg);
                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.Method = "POST";
request.ContentType = "multipart/form-data";
                    request.ContentLength = data.Length;但在
response = (HttpWebResponse)request.GetResponse();
时捕捉到了异常,403
求解决办法!!!!二进制新浪图片微博API

解决方案 »

  1.   

    ContentType 类型改成下面的试试。
    ContentType = "application/x-www-form-urlencoded";  
    Demo
    WebRequest req = WebRequest.Create("http://expert.csdn.net/Expert/topic/1581/1581934.xml"); 
    req.Method = "POST"; 
    req.ContentType = "application/x-www-form-urlencoded";
    byte[] postData = System.Text.Encoding.GetEncoding("gb2312").GetBytes( "temp=1063959&userid=654321" ); //Post的数据 
    req.ContentLength = postData.Length; 
    Stream postStream = req.GetRequestStream(); 
    postStream.Write(postData, 0, postData.Length); 
    postStream.Close(); 
    WebResponse res = req.GetResponse(); 
    System.Text.Encoding resEncoding = System.Text.Encoding.GetEncoding("gb2312"); //接收的编码 
    StreamReader reader = new StreamReader( res.GetResponseStream(),resEncoding ); 
    string html = reader.ReadToEnd();  //接收的Html 
    reader.Close(); 
    res.Close();