c# - Hyperwallet 服务在 postmant 中工作,但不能在带有 http 请求的 c# 代码中工作。?
问题描述
I am using **hyper wallet payment api** in one of my application.
An api of hyper wallet working Postman but not working with c# httpwebrequest calling.
服务调用后出现禁止的 403 错误。
Thank you
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));
string authInfo = "username" + ":" + "123456";
http.Method = "POST";
//http.Credentials = new NetworkCredential("username", "123456");
http.ContentType = "application/json";
http.Accept = "application/json";
http.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
http.Headers["Authorization"] = "Basic cmVzdGFwaXVzZXJAMTU1NDM3OTE2MTg6a2Fuc29mdEAxMjM=";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
//string currentUrl = HttpContext.Current.Request.Url.ToString();
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] bytes = encoding.GetBytes(data);
Stream newStream = http.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
var response = http.GetResponse();
var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var content = sr.ReadToEnd();
return content;
为什么此代码给出 403 禁止错误。但仍然在邮递员工作..?
解决方案
推荐阅读
- multithreading - 数组同步和多线程
- sql - Postgres LEFT JOIN 不返回空值?
- ruby-on-rails - 在carrierwave中为default_url图像分配一个版本
- php - 如何解决 Instagram mgp25 API 中所需的挑战?
- javascript - 函数中的事件侦听器存储在变量中
- php - 是否可以分页下一个和上一个链接以在特定 div 加载页面
- angularjs - 从使用 $http 服务的空响应中获取 HTTP 状态代码
- c++ - 在 C++ 中将函数应用于派生类的对象
- extjs - 同一网格单元格中的数字字段和下拉框
- javascript - Firebase Cloud Functions 身份验证 createUser 未知错误