0

私は人々がそこに名前を入れることができる名前フィールドを作ろうとしています、そしてそれはphpページに送られます。

私はこのコードでスペースなしでこれを動作させました...

- (IBAction)Submit:(id)sender {

    NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text];

    NSURL *url=[NSURL URLWithString:strURL];
    self.request=[NSURLRequest requestWithURL:url];

    self.nsCon=[[NSURLConnection alloc] initWithRequest:self.request delegate:self];


    NSLog(@"out put = %@", self.request);
}

しかし、スペースアダーフィックスを使用するとすぐに、ログに機能していると表示されていても、phpページで取得されません。

ここに画像の説明を入力してください

- (IBAction)Submit:(id)sender {

    NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=", nameField.text];

    strURL = [strURL stringByAppendingString:nameField.text];
    strURL = [strURL stringByAppendingString:@"'"];
    strURL = [strURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

    NSURL *url=[NSURL URLWithString:strURL];
    self.request=[NSURLRequest requestWithURL:url];

    self.nsCon=[[NSURLConnection alloc] initWithRequest:self.request delegate:self];


    NSLog(@"out put = %@", self.request);
}

構文エラーが発生したり、このメソッドに間違った方法でアプローチしたりしましたか?

私の.hファイル

#import <UIKit/UIKit.h>

@interface ContactViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, NSURLConnectionDataDelegate>{
    IBOutlet UITextField *nameField;
}
- (IBAction)Submit:(id)sender;
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (strong) NSURLConnection *nsCon;
@property (strong) NSURLConnection *request;
@property (strong) NSURLConnection *receivedData;

@end

ありがとう

4

1 に答える 1

2

stringByAddingPercentEscapesUsingEncodingリクエストする前に使用する必要があります。

NSURL *url = [NSURL URLWithString:
                 [[str stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]        
                 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

あなたのコードのためにこれを試してください。

- (IBAction)Submit:(id)sender {

    NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text];

    NSURL *url = [NSURL URLWithString:
                     [[strURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]        
                     stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

    self.request=[NSURLRequest requestWithURL:url];

    self.nsCon=[[NSURLConnection alloc] initWithRequest:self.request delegate:self];

    NSLog(@"out put = %@", self.request);
}
于 2013-03-06T16:51:40.523 に答える