gpt4 book ai didi

c# - Rightmove 实时数据馈送 (RTDF) asp.net 的集成

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:12 27 4
gpt4 key购买 nike

我正在将 rightmove 实时数据馈送 (rtdf) 集成到我的特性网站中,以便在 rightmove 网站上列出我的特性。我正在使用 asp.net web api 在 rightmove 列表上发布数据。他们向我提供了这些 SSL 文件 [.p12、.pem、.jks]。我已经在我的本地机器个人商店中导入了 .p12 证书,并在我的 http 请求中发送了它到 rightmove 提供的 rightmove 测试 api 链接。我从服务器收到以下错误。远程服务器返回错误:403 forbidden。

我检查了我在请求中成功加载的证书,下面是我的代码

public static string PostData(string data, string url)
{
String result = "";

try
{
byte[] bytebuffer = Encoding.UTF8.GetBytes(data);
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = bytebuffer.Length;
objRequest.ContentType = "application/json";
objRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0";
objRequest.PreAuthenticate = true;
objRequest.Accept = "application/json";
objRequest.ClientCertificates.Add(CertificateHelper.GetRightmoveApiX509Certificate());

using (Stream stream = objRequest.GetRequestStream())
{
stream.Write(bytebuffer, 0, bytebuffer.Length);
stream.Close();
}

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader streamReader = new StreamReader(objResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
// Close and clean up the StreamReader
streamReader.Close();
}
}
catch (Exception e)
{
result = "Exception: " + e.Message;
}
return result;
}

帮助我摆脱 403 forbidden 错误。

最佳答案

使用以下内容。我已经对其进行了测试,它在我的案例中运行良好。

// Grab Certificate
X509Certificate2 cert2 = new X509Certificate2(
AppDomain.CurrentDomain.BaseDirectory + "CertificateName.p12",
CertificatePasswordHere,
X509KeyStorageFlags.MachineKeySet);


var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.ClientCertificates.Clear();
httpWebRequest.ClientCertificates.Add(cert2);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(data);
streamWriter.Flush();
streamWriter.Close();
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}

关于c# - Rightmove 实时数据馈送 (RTDF) asp.net 的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36218712/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com