这就是我用.NET调用服务的方式:
var requestedURL = "https://accounts.google.com/o/oauth2/token?code=" + code + "&client_id=" + client_id + "&client_secret=" + client_secret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code";
HttpWebRequest authRequest = (HttpWebRequest)WebRequest.Create(requestedURL);
authRequest.ContentType = "application/x-www-form-urlencoded";
authRequest.Method = "POST";
WebResponse authResponseTwitter = authRequest.GetResponse();
Run Code Online (Sandbox Code Playgroud)
但是当调用此方法时,我得到:
异常详细信息:System.Net.WebException:远程服务器返回错误:(411)Length Required.
我该怎么办?
尝试通过C#桌面应用程序将文件上传到我的服务器时出现以下错误:"根据验证程序,远程证书无效." 这与SSL证书有关.它是由我的网站由Arvixe托管.这是我使用的代码:
public void Upload(string strFileToUpload)
{
FileInfo fiToUpload = new FileInfo(strFileToUpload);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.sd.arvixe.com/" + strDomain + "/wwwroot/OnlineGalleries/" + strOnlineGalleryName + "/Gallery/" + fiToUpload.Name);
request.EnableSsl = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("usr", "psw");
Stream sFTP = request.GetRequestStream();
FileStream file = File.OpenRead(strFileToUpload);
int length = 1024;
byte[] buffer = new byte[length];
int bytesRead = 0;
do
{
bytesRead = file.Read(buffer, 0, length);
sFTP.Write(buffer, 0, bytesRead);
}
while (bytesRead != 0);
file.Close();
sFTP.Close();
}
Run Code Online (Sandbox Code Playgroud)
如果我设置request.EnableSsl = false,此代码可以正常工作.我不知道该怎么做.我已经尝试将URI设置为ftps://和sftp://,但它们返回错误"无法识别URI前缀".任何帮助表示赞赏.