为什么我这webResponse总是有时候会失败

w2362233 2018-01-08 12:04:56
这是代码部分
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Security.Cryptography;
using System.Text;


namespace Whmcs
{
public class Call
{
private readonly string Username;
private readonly string Password;
private readonly string AccessKey;
private readonly string Url;
private readonly string UrlForSS;

public Call(string Username, string Password, string AccessKey, string Url)
{
this.Username = Username;
this.Password = Password;
this.AccessKey = AccessKey;
this.Url = Url + "/includes/api.php";
this.UrlForclient = Url;
}

private NameValueCollection BuildRequestData(NameValueCollection data)
{

NameValueCollection request = new NameValueCollection()
{
{ "username", Username},
{ "password", Password},
{ "accesskey", AccessKey },
{ "responsetype", "json"}
};

foreach(string key in data)
{
request.Add(key, data[key]);
}

return request;
}

public string MakgeCallFroclient(string urlforclient, NameValueCollection data,bool isUft8)
{
string u = UrlForclient + urlforclient;
if(isUft8)
return Encoding.UTF8.GetString(WebCall(u, data));
else
return Encoding.ASCII.GetString(WebCall(u, data));
}

public string MakeCall(NameValueCollection data)
{
return Encoding.ASCII.GetString(WebCall(Url, data));
}

private byte[] WebCall (string url,NameValueCollection data)
{
byte[] webResponse;

try
{
webResponse = new WebClient().UploadValues(url, BuildRequestData(data));

}
catch (Exception ex)
{
throw new Exception(I18N.GetString("Unable to connect to WHMCS API:"), new Exception(ex.Message.ToString()));
}
return webResponse;
}

private string CalculateMD5Hash(string input)
{
MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);

StringBuilder sb = new StringBuilder();
foreach (byte t in hash)
{
sb.Append(t.ToString("x2"));
}
return sb.ToString();
}

}
}
为什么我这webResponse总是有时候会失败
...全文
139 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
enaking 2018-01-08
  • 打赏
  • 举报
回复
你要先用ie的F12捕捉一下,是不是很有很多提交属性没加上去。
xuzuning 2018-01-08
  • 打赏
  • 举报
回复
总是会失败 : 检查代码 有时候会失败 : 失败时检查 http 协议头

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧