我想要一个名称字段,人们可以放在那里名称,它会发送到一个PHP页面。空间NSURL连接
我有这个工作没有与此代码的空间...
- (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
感谢
作为一个侧面说明,可能不会解决您的问题,而不是stringByReplacingOccurrencesOfString方法,你应该使用[unescapedString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]。 – 2013-03-06 16:54:14