将NSString上载到服务器时出现问题

将NSString上载到服务器时出现问题

本文介绍了将NSString上载到服务器时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用php和mysql获取一个特定的字符串上载,我从文本字段中获得了许多字符串,这些字符串将成功使用,这个特定的字符串是另一个viewcontroller中的标签中的文本.我可以使用NSLog看到文本,但由于某种原因它不会消失,我确信服务器端可以正常工作,因为我可以将其他字符串传递给mySQL中的该特定行.要从其他视图获取文本,我正在使用

I am struggling to get one particular string to upload, using php and mysql I have a number of strings from textfields that will successfully go, this particular string is the text from a label in another viewcontroller. I can see the text with NSLog but for some reason it will not go, I'm confident the server side is working properly as I can pass other strings to that particular row in mySQL.To get the text from the other view I am using

- (IBAction)submit:(id)sender;
    {

    GetLocation * getlocation =[[GetLocation alloc] initWithNibName:Nil bundle:nil];
    getlocation.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    getlocation.rwanswer=self.rwanswer.text;
    [self presentModalViewController:getlocation animated:YES];

    [getlocation release];
}

在第一个viewcontroller中,然后在要上传到服务器的视图中,我合成字符串.

in the first viewcontroller then in the view that is uploading to the server I synthesize the string.

NSString *rwanswer;
@property (nonatomic, copy) NSString *rwanswer;

我可以使用NSLog看到文本,但是由于某种原因,我无法将其上传.

I can see the text with NSLog but for some reason I cannot get it to upload.

-(IBAction)UploadData :(id)sender {


    NSString *appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];


    NSString *result =rwanswer;
    NSLog(@"result=%@", result);

    NSString *comment =comments.text;
    NSString *name = username.text;
    NSLog(@"name=%@", name);

    NSString *Website =[NSString stringWithFormat:@"http://www.ivectorn.com/Set/Submit.php?name=%@&comments=%@&appname=%@&results=%@", name, comment, appname,  result];
    [BackroundLoader loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:Website]]];

任何帮助都会很棒

推荐答案

我知道此问题.我认为问题出在您的网站字符串上.尝试登录为int,您会看到里面没有字符,您不能输入URL.如果这是您的问题,以下方法将为您提供帮助:

I know this problem. I think the problem is by your Website-String. Try to Log int and you will see, that there are characters inside you cannot put in a URL. The following method will help you if this is your problem:

- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding

代替

NSString *appname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];


NSString *result =rwanswer;
NSLog(@"result=%@", result);

NSString *comment =comments.text;
NSString *name = username.text;

对于以下内容:

NSString *appname = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //Or your String Encoding


NSString *result = [rwanswer stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //Or your String Encoding;
NSLog(@"result=%@", result);

NSString *comment =[comments.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //Or your String Encoding;
NSString *name = [username.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //Or your String Encoding;

我希望这会对您有所帮助.我前段时间也遇到了同样的问题.

I hope this will help you. I struggled with the same problem some time ago.

Sandro Meier

Sandro Meier

这篇关于将NSString上载到服务器时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:05