首页 > 解决方案 > 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 禁止错误。但仍然在邮递员工作..?

标签: c#

解决方案


推荐阅读