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 6621007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:10:56+00:00 2026-05-25T21:10:56+00:00

1)On Iphone, – (void) postData:(NSMutableData *)_body withAction:(NSString *)_action binary:(BOOL)_binary { [self stopProcess]; binary =

  • 0

1)On Iphone,

- (void) postData:(NSMutableData *)_body withAction:(NSString *)_action binary:(BOOL)_binary
{
    [self stopProcess];



    binary = _binary;

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    NSString *url = [NSString stringWithFormat:API_FORMAT, APP_SERVER, _action, [self getSession]];
    if (debug_switch) {
    NSLog(@"The action is %@", _action);
        NSLog(@"The accessing server API call Datafeed is %@", url);}
    [request setURL:[NSURL URLWithString:url]];
    [request setHTTPMethod:@"POST"];


    //TRACE(@"url: %@", url);

    if(_body != nil)
    {
        NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
        [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
        [request setHTTPBody:_body];
    }

    //con = [NSURLConnection connectionWithRequest:request delegate:self];

    if(con != nil) {
        [con release];
    }
    con = [[NSURLConnection alloc] initWithRequest:request delegate:self];

    if (con) 
    {
        dataDict = nil;
        loading = YES;
        if(receivedData == nil) {
            receivedData = [[NSMutableData data] retain];
        }
        [receivedData setLength:0];
    }

}

static NSString *boundary = @"---------------------------147378274664144922";

@implementation DataFeed

BOOL connectable = NO;

///////////////////////////////

- (NSMutableData *) initContentBody
{
    NSMutableData *body = [NSMutableData data];
    [body appendData:[self addFormData:@"uid" withString:[[UIDevice currentDevice] uniqueIdentifier]]];
    return body;
}


//////////////////////////

- (NSData *) addFormBoundary
{
    return [[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding];
}

//////////////////////////////////////////


- (NSData *) addFormData:(NSString *)_name withInt:(int)_value
{
    return [self addFormData:_name withString:[[NSNumber numberWithInt:_value] stringValue]];
}


- (NSData *) addFormData:(NSString *)_name withFloat:(float)_value
{
    return [self addFormData:_name withString:[[NSNumber numberWithFloat:_value] stringValue]];
}


- (NSData *) addFormData:(NSString *)_name withString:(NSString *)_value
{
    NSMutableData *body = [NSMutableData data];
    [body appendData:[self addFormBoundary]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\";\r\n\r\n%@", _name, _value] dataUsingEncoding:NSUTF8StringEncoding]];    
    return body;
}

- (NSData *) addFormData:(NSString *)_name filename:(NSString *)_filename withData:(NSData *)_data
{
    NSMutableData *body = [NSMutableData data];
    [body appendData:[self addFormBoundary]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", _name, _filename] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/zip\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithString:@"Content-Transfer-Encoding: binary\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:_data];    
    return body;
}

2)On Android,

public void executeHttpPost() throws Exception {
    String address = "";
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(address);

    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("key1", "value1"));
    pairs.add(new BasicNameValuePair("key2", "value2"));
    post.setEntity(new UrlEncodedFormEntity(pairs));

    HttpResponse response = client.execute(post);

}

The question, on body data of the android can it set to non json format, key-value pair? as you can see on iphone, body can be any parameters, doesn’t have to be key value pair.can you give an example on android where the post data can be non-json format?

  • 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-05-25T21:10:57+00:00Added an answer on May 25, 2026 at 9:10 pm

    You’re not constrained to UrlEncodedFormEntity, check out the “Known Indirect Subclasses” of the org.apache.http.HttpEntity interface (at the top of the page).

    The most commonly used ones are probably:

    • ByteArrayEntity: An entity whose content is retrieved from a byte array.
    • FileEntity: An entity whose content is retrieved from a file.
    • InputStreamEntity: A streamed entity obtaining content from an InputStream.
    • SerializableEntity: Takes an Serializable object and outputs its serialized form
    • StringEntity: An entity whose content is retrieved from a string.
    • and finally UrlEncodedFormEntity: An entity composed of a list of url-encoded pairs.

    (this list is not complete, check out the above link)

    Here’s some examples of how to use different types of entities:

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(address);
    
    // a string entity containing JSON:
    post.setEntity(new StringEntity("{ \"actually\" : [\"json\", \"this time\"]}");
    
    // or uploading an image file:
    post.setEntity(new FileEntity(new File("some/local/image.png"), "image/png");
    
    // or some random bytes:
    byte[] randomBytes = new byte[128];
    new Random().nextBytes(randomBytes);
    post.setEntity(new ByteArrayEntity(randomBytes);
    
    HttpResponse response = client.execute(post);
    ...
    

    Of course, don’t do this all at once, one call to setEntity() only! If you need MIME multipart requests, check out this tutorial by Vikas Patel (you’ll need an updated Apache HTTP Client JAR).

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

Sidebar

Related Questions

Iphone 4 MFMailComposeViewController MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; controller.mailComposeDelegate = self; [controller setMessageBody:@Welcome
iPhone resources by default show up in a Resources group that's visible in the
iPhone Human Interface Guidelines -- Do they apply for OpenGL games? GL games typically
Does iPhone support XML-RPC, Is their any open source framework which I can use?
Can iPhone applications compiled against 2.1 be successfully installed via iTunes on a 2.0
Some iPhone applications, such as Pandora seem to directly manipulate the hardware volume and
The iPhone SDK docs claim fopen() is a supported method of file access but
For iPhone game development, seems there are very like functions using CALayer and UIView,
The iPhone platform has a number of common gesture idioms. For example, there are
my iphone app crashes unexpectedly and looking at the crash log I can't tell

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.