Php 从服务器返回HTML而不是XML的SOAP API

Php 从服务器返回HTML而不是XML的SOAP API,php,json,xml,web-services,soap,Php,Json,Xml,Web Services,Soap,我可能不是唯一一个在Stackoverflow上发布此问题的人,但不幸的是,他们都没有解决我的问题 我已经开发了一个通过SOAP API连接到服务器的opencast移动应用程序,当通过Postman测试API时,它会返回正确的结果,但是当运行应用程序时,API会返回HTML而不是XML。它不会执行php文件并触发函数 -(void)loginRequest{ @try { NSMutableDictionary *params = [[NSMutableDi

我可能不是唯一一个在Stackoverflow上发布此问题的人,但不幸的是,他们都没有解决我的问题

我已经开发了一个通过SOAP API连接到服务器的opencast移动应用程序,当通过Postman测试API时,它会返回正确的结果,但是当运行应用程序时,API会返回HTML而不是XML。它不会执行php文件并触发函数

  -(void)loginRequest{
      @try {
          NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
          NSString *password = [NSString stringWithFormat:@"%@", [self md5:SOAP_PASSWORD]];
          [params setObject:SOAP_USER_NAME forKey:@"apiKey"];
          [params setObject:password forKey:@"apiPassword"];
          NSError *error = nil;
          NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:&error];
          NSString *jsonString;
          if(!jsonData){
  //            NSLog(@"Got an error: %@", error);
          }
          else
              jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
          NSString *parameters = [NSString stringWithFormat:@"<attributes xsi:type=\"xsd:string\">%@</attributes>", jsonString];
          NSString *envelope = [self createEnvelope:@"apiLogin" forNamespace:@"urn:Opencart" forParameters:parameters];
          NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: URL]];
          [request setHTTPMethod:@"POST"];
          NSMutableDictionary *defaultHeaders = [[NSMutableDictionary alloc] init];
          [defaultHeaders setValue:@"gzip" forKey:@"Accept-Encoding"];
          [defaultHeaders setValue:@"en, en-us;q=0.8" forKey:@"Accept-Language"];
          [defaultHeaders setValue:@"text/xml; charset=utf-8" forKey:@"Content-Type"];
          [defaultHeaders setValue:@"urn:Opencart_Api_Model_Server_HandlerAction" forKey:@"SOAPAction"];
          [defaultHeaders setValue:@"com.lognllc.Magento-iOS-Example/1.0.0 (unknown, iPhone OS 8.1, iPhone Simulator, Scale/2.000000)" forKey:@"User-Agent"];
          [request setAllHTTPHeaderFields:defaultHeaders];
          [request setHTTPBody:[envelope dataUsingEncoding:NSUTF8StringEncoding]];
          NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
          if(connection){
              webData = [NSMutableData data];
          }
          else{
            NSLog(@"The Connection is null error: %@", error);
          }
      }
      @catch (NSException *e) {
       NSLog(@"catching %@ reason 1 %@", [e name], [e reason]);
      }
  }
-(无效)登录请求{
@试一试{
NSMutableDictionary*params=[[NSMutableDictionary alloc]init];
NSString*密码=[NSString stringWithFormat:@“%@,[self md5:SOAP_密码]];
[params setObject:SOAP_USER_NAME forKey:@“apiKey”];
[params setObject:password forKey:@“apiPassword”];
n错误*错误=nil;
NSData*jsonData=[NSJSONSerialization dataWithJSONObject:params options:nsjsonwritingprettyptederror:&error];
NSString*jsonString;
if(!jsonData){
//NSLog(@“出现错误:%@”,错误);
}
其他的
jsonString=[[NSString alloc]initWithData:jsonData编码:NSUTF8StringEncoding];
NSString*参数=[NSString stringWithFormat:@]用于服务。
单击操作名称以查看其详细信息

HTML文件很长,因此我粘贴了其中的一部分。但是在日志末尾,我收到以下错误消息:

发生了一个错误{ NSXMLParserErrorColumn=14; NSXMLParserErrorLineNumber=77; NSXMLParserErrorMessage=“AttValue:\”或“预期的”\n”}

文件名为appserver.php,它应该执行该文件并根据调用的API返回XML结果

正确结果的示例应在演示服务器上进行测试:

{“横幅”:[{“标题”:“图像”,“链接”:“/index.php?route=product/product&;product_id=47”,“图像”:”http://domain.comm/image/data/banners/3.png},{“title”:“Testing”,“link”:“Image”,“Image”:http://domain.comm/image/data/banners/4.png},{“title”:“Something”,“link”:“/index.php?route=product/product&;path=57&;product_id=49”,“image”:"http://domain.comm/image/data/banners/6.png},{“title”:“asdgasdg”,“link”:“/index.php?route=product/product&;path=57&;product_id=49”,“image”:http://domain.comm/image/data/banners/5.png},{“title”:“Image”,“link”:“/index.php?route=product/product&;path=57&;product_id=49”,“Image”:http://domain.comm/image/data/banners/1.png“}],“模块”:{“特色”:[{“产品id”:“47”,“拇指”:”http://domain.com/image/cache/data/hp_1-187.5x187.5.jpg,“名称”:“HP

我再次粘贴了部分文件,而不是整个文件作为摘要,所以问题不会太长


我检查了服务器配置,发现服务器上安装了SOAP、XMLWriter和XMLReader,但错误仍然存在。在两周内试图解决此问题,但没有结果,这确实是一件令人头痛的事情。如果有人已经经历过这一问题,并且可以提供建议,我将非常感谢您的帮助。

经过一段时间的研究,我发现错误为a在客户端的服务器上,他将他的服务器配置为强制www重定向,因此每当来自非www域的请求都应该重定向到www,我更改了API URL调用并添加了“www”现在它正在加载应用程序。

首先,标题如何?您是否正确设置了所有需要的标题,如auth、content type、accept等。其次,有时php会在出现500错误或403(未经授权)时发送html。将您的html页面保存在pastebin上,并在此处提供链接感谢您的支持我发布了我的答案,但现在对于返回“文档末尾的nsxmlparser额外内容”的某些API函数调用,我出现了一个新错误同样,在我的服务器上测试时,它工作正常,但客户端服务器工作不正常。我尝试了所有可能的解决方案,但没有成功,请问有什么建议?
<html><head><title>NuSOAP: Opencart</title>
<style type="text/css">
    body    { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
    p       { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
    pre { background-color: silver; padding: 5px; font-family: Courier New; font-size: x-small; color: #000000;}
    ul      { margin-top: 10px; margin-left: 20px; }
    li      { list-style-type: none; margin-top: 10px; color: #000000; }
    .content{
    margin-left: 0px; padding-bottom: 2em; }
    .nav {
    padding-top: 10px; padding-bottom: 10px; padding-left: 15px; font-size: .70em;
    margin-top: 10px; margin-left: 0px; color: #000000;
    background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
    .title {
    font-family: arial; font-size: 26px; color: #ffffff;
    background-color: #999999; width: 100%;
    margin-left: 0px; margin-right: 0px;
    padding-top: 10px; padding-bottom: 10px;}
    .hidden {
    position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
    font-family: arial; overflow: hidden; width: 600;
    padding: 20px; font-size: 10px; background-color: #999999;
    layer-background-color:#FFFFFF; }
    a,a:active  { color: charcoal; font-weight: bold; }
    a:visited   { color: #666666; font-weight: bold; }
    a:hover     { color: cc3300; font-weight: bold; }
</style>
<script language="JavaScript" type="text/javascript">
<!--
// POP-UP CAPTIONS...
function lib_bwcheck(){ //Browsercheck (needed)
    this.ver=navigator.appVersion
    this.agent=navigator.userAgent
    this.dom=document.getElementById?1:0
    this.opera5=this.agent.indexOf("Opera 5")>-1
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6
    this.mac=this.agent.indexOf("Mac")>-1
    this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
    return this
}
var bw = new lib_bwcheck()
//Makes crossbrowser object.
function makeObj(obj){
    this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
    if(!this.evnt) return false
    this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
    this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
    this.writeIt=b_writeIt;
    return this
}
// A unit of measure that will be added when setting the position of a layer.
//var px = bw.ns4||window.opera?"":"px";
function b_writeIt(text){
    if (bw.ns4){this.wref.write(text);this.wref.close()}
    else this.wref.innerHTML = text
}
//Shows the messages
var oDesc;
function popup(divid){
    if(oDesc = new makeObj(divid)){
    oDesc.css.visibility = "visible"
    }
}
function popout(){ // Hides message
    if(oDesc) oDesc.css.visibility = "hidden"
}
//-->
</script>
</head>
<body>
<div class=content>
    <br><br>
    <div class=title>Opencart</div>
    <div class=nav>
        <p>View the <a href="/api/appserver.php?wsdl">WSDL</a> for the service.
        Click on an operation name to view it&apos;s details.</p>
        <ul><li><a href='#' onclick="popout();popup('apiLogin')">apiLogin</a></li><div id='apiLogin' class='hidden'>