Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:35:04+00:00 2026-06-03T07:35:04+00:00

I have writen the fellowing code: NSString *urlString = [NSString stringWithFormat:ADDRESS,action]; postStr = @user_name=Thomas

  • 0

I have writen the fellowing code:

NSString *urlString = [NSString stringWithFormat:ADDRESS,action];
postStr = @"user_name=Thomas Tan&phone=01234567891&password=123456";
NSData *myRequestData = [NSData dataWithBytes:[postStr UTF8String] length:[postStr length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: myRequestData];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 
NSLog(@"%@",responseString);

it works well,but now I want to use asihttprequest framework,so how to change the above code,I have writen the code,but it can’t get the correct result and just get the server error infomation.so what’s the problem?

NSString *urlString = [NSString stringWithFormat:ADDRESS,action];

NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *requeset = [ASIFormDataRequest requestWithURL:url];
[requeset setRequestMethod:@"POST"];
[requeset setPostValue:@"Thomas Tan" forKey:@"user_name"];
[requeset setPostValue:@"01234567891" forKey:@"phone"];
[requeset setPostValue:@"123456" forKey:@"password"];
[requeset startSynchronous];
NSError *error = [requeset error];
if (!error) {
    NSString *re = [requeset responseString];
    NSLog(@"%@",re);
}
NSLog(@"%@",error);

thank you in advance.

UPDATE:

NSString *urlString = [NSString stringWithFormat:ADDRESS,action];
NSURL *url = [NSURL URLWithString:urlString];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"POST"]; 
[request appendPostData:[@"user_name=Thomas Tan&phone=01234567891&password=123456" dataUsingEncoding:NSUTF8StringEncoding]];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
    NSString *re = [request responseString];
    NSLog(@"%@",re);
}
NSLog(@"%@",error);

I use the above code ,It also can’t get the same result,and error is not nil.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:35:06+00:00Added an answer on June 3, 2026 at 7:35 am

    Your ASIHTTP code is not doing the same thing as your NSURLConnection code.
    ASIFormDataRequest will automatically:

    • set the Content-Type header to application/x-www-form-urlencoded
    • URL-encoded your parameters

    That’s usually exactly what you want, but if you’re getting the correct behavior with your NSURLConnection code and incorrect with ASIHTTP, then you need to change to a custom ASIHTTP POST and use ASIHTTPRequest, not ASIHTTPFormDataRequest, and then manually set the Conten-type back to application/x-www-form-urlencoded:

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setRequestMethod:@"POST"]; 
    [request addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];
    [request appendPostData:[@"user_name=Thomas Tan&phone=01234567891&password=123456" dataUsingEncoding:NSUTF8StringEncoding]];
    

    Doing this, and inspecting exactly what was sent to the server using Wireshark, I can see that the POST data sent is still not quite identical (ASIHTTP on the left, NSURLConnection on the right):

    post diff

    But the content type, length, and actual data is identical.
    At this point, I’d expect your server to return the same result.
    If it still doesn’t, you can edit the ASIhTTP request parameters to match.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code. But it is removing only &nbsp; not <br>
I have writen the following code but when i execute him i get this
I have successfully created video from images using the following code -(void)writeImageAsMovie:(NSArray *)array toPath:(NSString*)path
I have writen the following code but from some reason i cant get the
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
I have written a following code to get just the file name without extension
I have written the following code choice /m Do you want to add another
i have written the following code: As you can see there is a for
I have written the following code in Perl. I want to iterate through a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.