Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从邮递员而不是从c#代码发出的Post请求_C#_Httpwebrequest_Postman_Restsharp - Fatal编程技术网

从邮递员而不是从c#代码发出的Post请求

从邮递员而不是从c#代码发出的Post请求,c#,httpwebrequest,postman,restsharp,C#,Httpwebrequest,Postman,Restsharp,Post请求似乎在邮递员那里工作,但同样的事情在c代码中不起作用。但是,当我尝试从本地系统运行相同的代码时,它会返回响应,但当我从服务器尝试时,它不工作并引发异常,底层连接已关闭:在上发生意外错误 一封信 我已经加入了安全协议来解决这个问题,但它没有帮助 C#代码: var client = new RestClient("https://openweb.nlb.gov.sg/ows/CatalogueService.svc"); ServicePointManager.SecurityPro

Post请求似乎在邮递员那里工作,但同样的事情在c代码中不起作用。但是,当我尝试从本地系统运行相同的代码时,它会返回响应,但当我从服务器尝试时,它不工作并引发异常,底层连接已关闭:在上发生意外错误 一封信

我已经加入了安全协议来解决这个问题,但它没有帮助

C#代码:

var client = new RestClient("https://openweb.nlb.gov.sg/ows/CatalogueService.svc");

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;

var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("content-length", "714");
request.AddHeader("accept-encoding", "gzip, deflate");
request.AddHeader("cookie", "NSC_PQFOXFC-80=ffffffffaf1617ac45525d5f4f58455e445a4a423660; ASP.NET_SessionId=t12ibw24lljs5s2ktqrfrx45; NSC_PQFOXFC-443=ffffffffaf1617af45525d5f4f58455e445a4a42378b");
request.AddHeader("Host", "openweb.nlb.gov.sg");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "*/*");
request.AddHeader("SOAPAction", "http://www.nlb.gov.sg/ws/CatalogueService/ICatalogueService/Search");
request.AddHeader("Content-Type", "text/xml;charset=utf-8");
request.AddParameter("undefined", "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body \r\nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n<SearchRequest xmlns=\"http://www.nlb.gov.sg/ws/CatalogueService\">\r\n<APIKey>UFJPRC1EU1RBMjAxODpEU1RBQE9wM25XM2JOTEIhQCM=</APIKey>\r\n<SearchItems>\r\n<SearchItem>\r\n<SearchField>keywords</SearchField>\r\n<SearchTerms>blue ocean strategy</SearchTerms>\r\n</SearchItem>\r\n</SearchItems>\r\n<ContentType>eBooks</ContentType>\r\n<DataFrom>Apabi,Ebrary,Gale,LMS,Netlibrary,NHB,NLB,Overdrive,Wel</DataFrom>\r\n<Modifiers>\r\n<StartRecordPosition>0</StartRecordPosition>\r\n<MaximumRecords>20</MaximumRecords>\r\n</Modifiers>\r\n</SearchRequest>\r\n</s:Body>\r\n</s:Envelope>", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

虽然我怀疑它是否相关,但您可能不应该发送两次
缓存控制
。只需简单回顾一下,请确认或更正:本地邮递员=>本地服务器工作,本地点网=>本地服务器工作,本地邮递员=>远程服务器工作,本地点网=>远程服务器故障。这是正确的吗?远程邮递员工作,远程服务器dotnet故障虽然我怀疑这与否,但您可能不应该发送
缓存控制
两次。只需简单回顾一下,请确认或更正:本地邮递员=>本地服务器工作,本地dotnet=>本地服务器工作,本地邮递员=>远程服务器工作,本地dotnet=>远程服务器故障。对吗?远程邮递员工作,远程服务器dotnet失败
System.Net.WebException: The underlying connection was closed: An unex
pected error occurred on a send. ---> System.IO.IOException: Authentication fail
ed because the remote party has closed the transport stream.
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes
, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocol
Request asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToke
n message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, A
syncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byt
e[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyRes
ult)
   at System.Net.TlsStream.CallProcessAuthentication(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionCo
ntext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state)
   at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
   at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.ConnectStream.WriteHeaders(Boolean async)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest)
   at RestSharp.Http.PostPutInternal(String method)
   at RestSharp.Http.AsPost(String httpMethod)
   at RestSharp.RestClient.DoExecuteAsPost(IHttp http, String method)
   at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func
`3 getResponse)