0

userName と Password で構成される URL を解析する方法。

基本的に私はXMLの解析を知っています...しかし、私はそれでデータを取得していません..

そのようなURLを解析するのを手伝ってくれる人はいますか...

前もって感謝します..

4

3 に答える 3

4

2 つの問題があるかもしれません:-

1 デリゲートでパスワードとユーザー名を指定しなかったため、正しいデータを受信して​​いません

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

Like This を NSURLConnection のデリゲートとして実装します (これを使用している場合)。

#define LOGIN     @"RFC_ESERVICE"
#define PASSWORD  @"adm5ls@w"

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{
        if ([challenge previousFailureCount] == 0) 
        {
            NSURLCredential *credential = [NSURLCredential credentialWithUser:LOGIN
                                                                     password:PASSWORD
                                                                  persistence:NSURLCredentialPersistenceNone];
            [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
        }
}

2 データを受け取っても解析できない場合は、コードを投稿してください。また、XML は WSDL のようですが、どの情報を解析しますか?

于 2013-03-18T09:11:02.037 に答える
3

これは NSXMLParser を使用する方法です:

In your .h file declare :

NSMutableData       *webPortFolio;
NSMutableString     *soapResultsPortFolio;
NSURLConnection     *conn;

//---xml parsing---

NSXMLParser         *xmlParserPortFolio;
BOOL                elementFoundPortFolio;
NSMutableURLRequest *req;

NSString            *theXMLPortFolio;
NSString            *strSoapMsg;
UIAlertView         *alertView;

.m ファイルで次のコードを使用します。

-(void)callURL
{
      NSString *soapMsg = [NSString stringWithFormat:@"email=%@&pass=%@&type=activate",txt_UserName.text,txt_Password.text]; //Add your parameters here.

      //---print it to the Debugger Console for verification---


      NSString *str_url = [ NSString stringWithFormat:@"%@login",xmlWebservicesUrl]; //Your URL here
      NSURL *url = [NSURL URLWithString:str_url];
      req = [NSMutableURLRequest requestWithURL:url];

      NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
  [req addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
      [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];

      [req setHTTPMethod:@"POST"];
      [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
     //Your logic to call URL.

     conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
     if (conn)
     {
         webPortFolio = [[NSMutableData data] retain];
     }
}
And to handle the response you can use following functions :

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

}

-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error
{

}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
}

//---when the start of an element is found---
-(void)  parser:(NSXMLParser *) parser 
didStartElement:(NSString *) elementName 
   namespaceURI:(NSString *) namespaceURI 
  qualifiedName:(NSString *) qName
     attributes:(NSDictionary *) attributeDict
{
}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
    NSLog(@"Parser error %@ ",[parseError description]);
}


//---when the end of element is found---
-(void)parser:(NSXMLParser *)parser 
didEndElement:(NSString *)elementName 
 namespaceURI:(NSString *)namespaceURI 
qualifiedName:(NSString *)qName
{
}
于 2013-03-18T09:21:53.547 に答える
1
NSString *urlSt=@"https://ecservices.wasl.ae/sap/bc/srt/wsdl/bndg_514403C105C32C67E10000000AF00316/wsdl11/allinone/ws_policy/document?sap-client=100";

NSMutableURLRequest *theRequest=[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlSt]];

NSString *authStr = [NSString stringWithFormat:@"RFC_ESERVICE:adm5ls@w"];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodingWithLineLength:80]];
[theRequest setValue:authValue forHTTPHeaderField:@"Authorization"];

NSLog(@"Request is %@",theRequest);

[_webview loadRequest:theRequest];
于 2013-03-18T09:40:16.517 に答える