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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:37:26+00:00 2026-06-14T22:37:26+00:00

I’m developing an Ipad app. I have to use the POST method to sent

  • 0

I’m developing an Ipad app. I have to use the POST method to sent request to the Java server, then, the Java server will produce an outputstream of an bufferedimage. How can I receive this bufferedimage using objective-c?

the POST method’s code:

NSURL * url = [NSURL URLWithString:urlString];
_request = [NSMutableURLRequest requestWithURL:url];

[_request setHTTPMethod:@"POST"];
[_request setValue:[NSString stringWithFormat:cmdString] forHTTPHeaderField:@"cmd"];
[_request setValue:[NSString stringWithFormat:paramString] forHTTPHeaderField:@"param"];

[NSURLConnection connectionWithRequest:_request delegate:self];

the Java server’s code:

    OutputStream os=http.getResponseBody();
    String cmd=http.getRequestHeaders().getFirst("cmd");
    int cnt=Integer.valueOf(http.getRequestHeaders().getFirst("param"));
    System.out.println(cmd+"   "+cnt);
    int w,h;
    http.sendResponseHeaders(200,0);
    if(cmd.equals("1"))
    {
        w=512;
        h=512;
        idlmanager idl=new idlmanager();
        idl.createObject();
        byte[] buf=new byte[w*h*3+1];
        JIDLArray idlBuf=new JIDLArray(buf);
        JIDLNumber r=idl.UPDATEIMAGE(idlBuf,new JIDLInteger(1), new JIDLInteger(cnt));
        buf=(byte[]) idlBuf.arrayValue();
        int i,j;
        int[] data =new int[w*h];
        for(i=0;i<w*h;i++)
        {           
            data[i]=((buf[i*3]+256)%256)*256*256+((buf[i*3+1]+256)%256)*256+(buf[i*3+2]+256)%256;
        }

        int[] mask={255*256*256,255*256,255};
        ColorModel cm=new DirectColorModel(24,255*256*256 , 255*256,255);
        SampleModel sm=new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,w,h,mask);          
        DataBuffer db = new DataBufferInt(data, w*h);
        WritableRaster rast=Raster.createWritableRaster(sm,db, new Point(0,0));

        BufferedImage bufImg= new BufferedImage(cm, rast, false, null);
        ImageIO.write(bufImg, "png", os);
    }else if(cmd.equals("2")){....}
  • 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-14T22:37:27+00:00Added an answer on June 14, 2026 at 10:37 pm

    the easiest way is to use sendSynchronousRequest:returningResponse:error: from NSURLConnection.

    __autoreleasing NSError *error = nil;
    __autoreleasing NSURLResponse *response = nil;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
    [responseData writeToFile:savePath atomically:YES];
    

    Assume savePath is a NSString contains a valid path.

    if you want to use connectionWithRequest:delegate: as mentioned in your code, you will have to implement the following delegate methods:

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
        NSLog(@"Error: %d %@", [error code], [error localizedDescription]);
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        responseData = [NSMutableData data];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [responseData appendData:data];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        [responseData writeToFile:savePath atomically:YES]; 
    }
    

    here responseData is an instance variable declared with:

    NSMutableData *responseData;
    

    and your class must conforms the NSURLConnectionDataDelegate and NSURLConnectionDelegate protocols.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.