dshnx48866 2013-02-21 05:29
浏览 62
已采纳

iphone发布请求标题

I am going to develop web services based on REST API. It is my first project of web services.

I have a question regarding web services-iPhone app.

Suppose when a user logged in using iPhone app his will get authentication token.

Using this token he/she wiil be authorized to use futher operation of app . I am planing about that iPhone app needs to be send hearders along with post/get request method with authentication key in herders.

Request looks like: www.mydomaoin.com

But to authorize on server I need to pass special parameters to Header of request:

Headers: X-Testing-Auth-Secret: kI7wGju76kjhJHGklk76
Headers: Content-Type : application/json

which will be used in controller (zend framework)

public function preDispatch()  
{
    $request = new Zend_Controller_Request_Http();
    $key = $request->getHeader('X-Testing-Auth-Secret');
    $type = $request->getHeader('Content-Type');
}

I don't know an iPhone capable for sending headers or not. As as in case of android.

I am a php developer

Please help me

  • 写回答

5条回答 默认 最新

  • doucheyi1347 2013-02-21 07:04
    关注

    There are some delegate methods you can use.

    -(void) parser:(NSXMLParser *) parser
    didStartElement:(NSString *) elementName``
      namespaceURI:(NSString *) namespaceURI
     qualifiedName:(NSString *) qName
       attributes:(NSDictionary *) attributeDict {
    
        if( [elementName isEqualToString:@"AddGeneralInformationResult"])
       {
        if (!soapResults)
        {
            soapResults = [[NSMutableString alloc] init];
        }
        elementFound = YES;
       }
    
    
        }
    
      -(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
       {
    if (elementFound)
    {
        [soapResults appendString: string];
    }
    }
    
    -(void)parser:(NSXMLParser *)parser
     didEndElement:(NSString *)elementName
      namespaceURI:(NSString *)namespaceURI
      qualifiedName:(NSString *)qName
     {
    
     if ([elementName isEqualToString:@"AddGeneralInformationResult"])
     {
        elementFound = NO;
        //NSLog(@"AddGeneralInformationResult %@",soapResults);
        if([soapResults isEqualToString:@"true"])
        {
    
    
      [objDB updateDatabaseTable:@"GeneralInformation":@"Yes":
        [[arrGenralInfo          objectAtIndex:0] intValue]];
        }
        [soapResults setString:@""];
        elementFound = FALSE;
       }
    
    
      }
     -(void) connection:(NSURLConnection *) connection
     didReceiveResponse:(NSURLResponse *) response {
     [webData setLength: 0];
    
    //NSLog(@"receive response");
      }  
    
     -(void) connection:(NSURLConnection *) connection
     didReceiveData:(NSData *) data {
      [webData appendData:data];
      }
    
        -(void) connection:(NSURLConnection *) connection
           didFailWithError:(NSError *) error {
    
        //NSLog(@"Server error");
    
        }
    
      -(void) connectionDidFinishLoading:(NSURLConnection *) connection {
         //NSLog(@"DONE. Received Bytes: %d", [webData length]);
          NSString *theXML = [[NSString alloc]
                        initWithBytes: [webData mutableBytes]
                        length:[webData length]
                        encoding:NSUTF8StringEncoding];
    //---shows the XML---
    //NSLog(@"%@",theXML);
    
    // [activityIndicator stopAnimating];
    if (xmlParser)
    {
    
    }
    xmlParser = [[NSXMLParser alloc] initWithData: webData];
    [xmlParser setDelegate: self];
    [xmlParser setShouldResolveExternalEntities:YES];
    [xmlParser parse];
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输