将参数传递给Web服务工作代码 [英] passing parameter to the web service working code

查看:93
本文介绍了将参数传递给Web服务工作代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次尝试使用soap方法,但这次我下载了查尔斯并观察了我从我的代码创建的请求。 Chales显示无法解析数据(org.xml.sax.saxparser异常:prolog中不允许内容)

again i am trying with soap method, but this time i downloaded the charles and observe the request that i create from my code. Chales showing "failed to parse data(org.xml.sax.saxparser exception:content is not allowed in prolog)"

这是我的代码:

   NSString *soapMsg = [[NSString alloc] initWithFormat:@"\n"
                         "\n"
                         ""
                         "\n"
                         "%@\n"
                         "%@\n"                                                                                                              
                         "%@\n"
                         "%@\n"
                         "\n"
                         "\n"
                         "\n",str1,str2,str3,str4];                       
        NSLog(soapMsg);

    NSURL *url = [NSURL URLWithString:@"http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation"];
    NSLog(@"url. . . .%@", url);
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];    
    NSLog(@"req....%@", req); 
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];


    NSLog(@"msgLength. . .%@", msgLength);
    [req addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [req addValue: @"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"];
    [req addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"req....%@", req);
    NSError *error;
    NSURLResponse *response;
    //NSData *urlData=[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];


     NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];

     if( theConnection )
     {
         //webData = [[NSMutableData data] retain];
         NSLog(@"theConnection is OK");
     }
     else
     {
         NSLog(@"theConnection is NULL");
     }





     if(!response){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Failed to Connect to the Internet" delegate:self  cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }

    else{
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Connection Successful" message:@"Connected to the Internet" delegate:self  cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert1 show];
        [alert1 release];

    }
} 


帮助!!提前谢谢!!

help!! thanks in advance!!

推荐答案

您在询问如何在项目中包含ASIHTTPRequest,对吧?复制并粘贴项目文件夹中的ASIHTTPRequest文件夹,并将其添加到您的代码中:

You are asking how to include ASIHTTPRequest in your project, right? Copy and paste ASIHTTPRequest's folder in your project's folder and add this in your code:

#import "ASIHTTPRequest.h"

请注意 ASIHTTPRequest 是一个外部库,不是iOS SDK的一部分。

Note that ASIHTTPRequest is an external library and not part of the iOS SDK.

这篇关于将参数传递给Web服务工作代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆