远程服务器返回错误:(403) 禁止。错误?
下面是我的代码..我收到错误 -“远程服务器返回错误:(403) 禁止。”..:
TimeSpan t = DateTime.Now - new DateTime(1970, 1, 1);
string content = @"<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:gphoto='http://schemas.google.com/photos/2007' >
<title type='text'>Trip To Italy</title>
<summary type='text'>This was the recent trip I took to Italy.</summary>
<gphoto:location>Italy</gphoto:location>
<gphoto:access>public</gphoto:access>
<gphoto:timestamp>" + t.Milliseconds.ToString() + @"</gphoto:timestamp>
<media:group><media:keywords>italy</media:keywords></media:group>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/photos/2007#album'></category>
</entry>";
ServicePointManager.ServerCertificateValidationCallback = new
RemoteCertificateValidationCallback(delegate(object sender2, X509Certificate
certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
});
string url = "https://www.picasaweb.google.com/data/feed/api/user/default";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/atom+xml";
request.Headers.Add(HttpRequestHeader.Authorization, "AuthSub token=\"" +
Session["token"].ToString() + "\"");
request.Headers.Add("GData-Version", "2.0");
byte[] send = System.Text.UTF8Encoding.UTF8.GetBytes(content);
request.ContentLength = send.Length;
int bytesRead = 0;
Stream requestStream = request.GetRequestStream();
while (send.Length - bytesRead > 1)
requestStream.Write(send, bytesRead++ , 1); //Edited
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader responseReader = new StreamReader(response.GetResponseStream());
string responseStr = responseReader.ReadToEnd();
请帮助:)
below is my code..I get an error -"The remote server returned an error: (403) Forbidden."..:
TimeSpan t = DateTime.Now - new DateTime(1970, 1, 1);
string content = @"<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:gphoto='http://schemas.google.com/photos/2007' >
<title type='text'>Trip To Italy</title>
<summary type='text'>This was the recent trip I took to Italy.</summary>
<gphoto:location>Italy</gphoto:location>
<gphoto:access>public</gphoto:access>
<gphoto:timestamp>" + t.Milliseconds.ToString() + @"</gphoto:timestamp>
<media:group><media:keywords>italy</media:keywords></media:group>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/photos/2007#album'></category>
</entry>";
ServicePointManager.ServerCertificateValidationCallback = new
RemoteCertificateValidationCallback(delegate(object sender2, X509Certificate
certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
});
string url = "https://www.picasaweb.google.com/data/feed/api/user/default";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/atom+xml";
request.Headers.Add(HttpRequestHeader.Authorization, "AuthSub token=\"" +
Session["token"].ToString() + "\"");
request.Headers.Add("GData-Version", "2.0");
byte[] send = System.Text.UTF8Encoding.UTF8.GetBytes(content);
request.ContentLength = send.Length;
int bytesRead = 0;
Stream requestStream = request.GetRequestStream();
while (send.Length - bytesRead > 1)
requestStream.Write(send, bytesRead++ , 1); //Edited
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader responseReader = new StreamReader(response.GetResponseStream());
string responseStr = responseReader.ReadToEnd();
please help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下代码
,这里您将发送第一个字节,然后是前两个字节,然后是前三个字节,依此类推。请尝试以下方法(未经测试):
Look at the code
Here you're sending the first byte, then the first two, then the first three, and so on. Try the following instead (not tested):