iPhone 中的其余 Web 服务

发布于 2024-12-02 11:21:57 字数 535 浏览 0 评论 0原文

我现在有问题。我需要将 transactionID 和用户密码传递给休息服务,并且它应该返回 true/false 值(以 XML 格式)。然而,它一直在返回我(空)..我完全迷失了,请帮忙。

    NSString *urlString = [NSString stringWithFormat:@"https://10.124.128.93:8443/axis2/services/C3WebService/completeWithdrawal  Transaction?transactionId=%@&password=%@", _transactionID.text, _userPassword.text];

    NSURL *url = [[NSURL alloc] initWithString:urlString];
    NSString *result = [[NSString alloc] initWithContentsOfURL:url];


    NSLog(@"%@",result );

我的结果不断地返回空值。我如何从这里继续?

I have a problem now. I need to pass an transactionID and an user password to a rest service and it is suppose to return me a true/false value (in XML format). However, it is consistently returning me (null).. I am totally lost some one please help.

    NSString *urlString = [NSString stringWithFormat:@"https://10.124.128.93:8443/axis2/services/C3WebService/completeWithdrawal  Transaction?transactionId=%@&password=%@", _transactionID.text, _userPassword.text];

    NSURL *url = [[NSURL alloc] initWithString:urlString];
    NSString *result = [[NSString alloc] initWithContentsOfURL:url];


    NSLog(@"%@",result );

My result is constantly returning me null. How do i continue from here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与之呼应 2024-12-09 11:21:57
.h:
    NSMutableData *responseData;

.m:
    - (void)load {
        NSURL *myURL = [NSURL URLWithString:@"https://10.124.128.93:8443/axis2/services/C3WebService/completeWithdrawal  Transaction?transactionId=%@&password=%@", _transactionID.text, _userPassword.text];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
                                                 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                             timeoutInterval:60];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    responseData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [responseData release];
    [connection release];
    [textView setString:@"Unable to fetch data"];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSLog(@"Succeeded! Received %d bytes of data",[responseData
                      `enter code here`                             length]);
    NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];

}
.h:
    NSMutableData *responseData;

.m:
    - (void)load {
        NSURL *myURL = [NSURL URLWithString:@"https://10.124.128.93:8443/axis2/services/C3WebService/completeWithdrawal  Transaction?transactionId=%@&password=%@", _transactionID.text, _userPassword.text];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
                                                 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                             timeoutInterval:60];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    responseData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [responseData release];
    [connection release];
    [textView setString:@"Unable to fetch data"];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSLog(@"Succeeded! Received %d bytes of data",[responseData
                      `enter code here`                             length]);
    NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];

}
药祭#氼 2024-12-09 11:21:57

考虑使用 NSURLConnection,它具有结果回调和获取详细错误详细信息的回调。它也不会在 UI 线程上执行(在请求期间不会挂起 UI)。

 NSURL *url = [NSURL URLWithString:@"http://www.mysite.com"];

 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

 [request setHTTPMethod:@"GET"];
 [[NSURLConnection alloc] initWithRequest:request delegate:self];

然后你可以实现委托方法来获取错误、数据和其他详细信息:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"result: %@", responseString);

    [responseString release];
}

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
      NSLog(@"error - read error object for details");
}

Consider using NSURLConnection which has a callback for the result and also a callback to get detailed error details. It als doesn't execute on the UI thread (doesn't hang UI during the request).

 NSURL *url = [NSURL URLWithString:@"http://www.mysite.com"];

 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

 [request setHTTPMethod:@"GET"];
 [[NSURLConnection alloc] initWithRequest:request delegate:self];

Then you can implement the delegate methods to get the error, the data and other details:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSLog(@"result: %@", responseString);

    [responseString release];
}

- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
      NSLog(@"error - read error object for details");
}
素食主义者 2024-12-09 11:21:57

您可以尝试使用“initWithContentsOfURL:encoding:error:”代替并检查“error”。另外,使用 Charles 或其他 http 嗅探器并将结果与​​直接浏览器请求进行比较(您是否在浏览器中检查结果?)

You might try using "initWithContentsOfURL:encoding:error:" instead and check "error". Also, use Charles or other http sniffer and compare results to a straight browser request ( did you check results in a browser?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文