-1

iPhoneアプリからサーバーにデータを投稿していますが、「過剰な不正アクセス」に関するポストラインコードの読み取り中に例外が発生します。4つの変数データの送信に使用する同じコードで、ポストに変数を追加するとエラーが発生します.

    NSString*category=titleCategory;
NSString*sub_Category=titleSubCategory;
NSString*content_Type=@"Audio";

content_Title=TitleTextField.text;
NSString*content_Title=content_Title;
NSString*publisher=@"Celeritas";
    content_Description=descriptionTextField.text;
NSString*content_Description=content_Description;

NSString*content_ID=@"10";
NSString*content_Source=@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/productivo/pro/ali.wav";


NSString *post =[[NSString alloc] initWithFormat:@"category=%@&sub_Category=%@&content_Type=%@&content_Title=%@&publisher=%@&content_Description=%@&content_ID=%@&content_Source=%@",category,sub_Category,content_Type,content_Title,publisher,content_Description,content_ID,content_Source];


NSURL *url=[NSURL URLWithString:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/addData.php"];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];


NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",data);

以下はコードを壊す行です

    NSString *post =[[NSString alloc] initWithFormat:@"category=%@&sub_Category=%@&content_Type=%@&content_Title=%@&publisher=%@&content_Description=%@&content_ID=%@&content_Source=%@",category,sub_Category,content_Type,content_Title,publisher,content_Description,content_ID,content_Source];
4

3 に答える 3

0

次のコードは、プロジェクトと.hファイルでテストするときに非常に役立ちます

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController{
    NSURLConnection *connection;
    NSMutableData *responseData;
}

@end

In.mファイル

 - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    NSString*category=@"Cat1";
    NSString*sub_Category=@"Title";
    NSString*content_Type=@"Audio";

    NSString* content_Title=@"Test";

    NSString*publisher=@"Celeritas";

    NSString*content_Description=@"Content Description";

    NSString*content_ID=@"10";
    NSString*content_Source=@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/productivo/pro/ali.wav";


    NSString*post = [NSString stringWithFormat:@"category=%@&sub_Category=%@&content_Type=%@&content_Title=%@&publisher=%@&content_Description=%@&content_ID=%@&content_Source=%@",category,sub_Category,content_Type,content_Title,publisher,content_Description,content_ID,content_Source];

    NSURL *url=[NSURL URLWithString:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/addData.php"];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];


    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];

    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:postData];



    connection=[NSURLConnection connectionWithRequest:request delegate:self];
    if(connection){
        responseData=[NSMutableData data];
    }
}

#pragma NSUrlConnection Delegate Methods

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength: 0];
}

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

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
//    [delegate APIResponseArrived:NULL];

}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString =[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//    [delegate APIResponseArrived:responseString ];
    NSLog(@"%@",responseString);
}

このコードはあなたの問題を解決します。

于 2013-03-20T09:19:39.320 に答える
0

私は実際に彼らの無効なアドレスに変数の割り当ての問題があったという質問の解決策を得ました。それがアクセスに悪いエラーを与えていた理由です。私は値を直接割り当てたので、うまくいきました

  NSString*category=@"Category";
NSString*sub_Category=@"Working";
NSString*content_Type=@"Audio";

NSString*content_Title=@"Content Title";
NSString*publisher=@"Celeritas";
NSString*content_Description=@"ContentDescription";




NSString*content_ID=@"10";
NSString*content_Source=@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/productivo/pro/ali.wav";


NSString *post =[[NSString alloc] init];


post = [NSString stringWithFormat:@"category=%@&sub_Category=%@&content_Type=%@&content_Title=%@&publisher=%@&content_Description=%@&content_ID=%@&content_Source=%@",category,sub_Category,content_Type,content_Title,publisher,content_Description,content_ID,content_Source];


NSURL *url=[NSURL URLWithString:@"http://www.celeritas-solutions.com/pah_brd_v1/productivo/addData.php"];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
于 2013-03-20T08:22:35.167 に答える