必须从php
调用GET-WS
Url:https://testWS/CompanyGeneralInformation?IdUser=123&CUI=345
当query-string被添加为静态时,它工作正常。$out = file_get_contents("https://testWS/CompanyGeneralInformation?CUI=345&IdUser=123")
但是当提前计算并作为参数传递时,得到了错误
$id=123;
$qs="https://testWS/CompanyGeneralInformation?CUI=345&IdUser=".$id;
$out = file_get_contents($qs);
//but this is OK
//$qs="https://testWS/CompanyGeneralInformation?CUI=345&IdUser=123";
//$out = file_get_contents($qs);
错误:
Warning: file_get_contents(https://...CompanyGeneralInformation?IdUser=<?xml version="1.0" encoding="utf-8"?>
<int xmlns="http://tempuri.org/">123</int>&CUI=567)
: Failed to open stream: HTTP request failed! HTTP/1.1 400
注意:似乎id从服务器端转换为XML ??此外,使用POST(通过curl)获得自定义参数的相同问题,当静态总是工作
时Post via curl (error)
$str=strval("CUI=".$cui."&IdUser=".$id);
curl_setopt($ch, CURLOPT_POSTFIELDS,"$str"); //or either $str
System.Web.HttpRequestValidationException: A potentially dangerous Request.
Form value was detected from the client (IdUser="<?xml version="1.0" ...").
at System.Web.HttpRequest.ValidateString(String value, String collectionKey,
RequestValidationSource requestCollection) at
System.Web.HttpRequest.ValidateHttpValueCollection(HttpValueCollection collection,
RequestValidationSource requestCollection) at System.Web.HttpRequest.get_Form() at
System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request) at
System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at
System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
注:WS文档指定:GET /link/CompanyGeneralInformation?CUI=string&IdUser=string HTTP/1.1
响应是xml(但现在不相关)。
注意(错误来源):Response is xml (but irrelevant now)
:非常相关,因为首先使用WS获取id而没有转换为变量后得到了错误。然后传递id(实际上是xml,因为没有解析)。
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
...
请告诉我可能是什么问题。
从回显的注释和提到的错误来看,这似乎只是一个问题,在通过URL传递XML之前没有从XML中提取所需的信息。