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

  • Home
  • SEARCH
  • 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 9216583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:26:55+00:00 2026-06-18T02:26:55+00:00

I am trying to execute a https post request using curl. When I execute

  • 0

I am trying to execute a https post request using curl. When I execute this request, I am neither getting any response nor any error or exception. Help or any clue about what’s going wrong here is appreciated. Thanks.

curl command line format :

    curl -X POST \
-F 'image=@filename.png;type=image/png' \
-F 'svgz=@filename.svgz;type=image/svg+xml' \
-F 'json={ 
    "text" : "Hello world!",
    "templateid" : "0010",
    "timestamp" : "1342683312", 
    "location" : [ 37.7793, -122.4192 ],
    "facebook" :
    {
        "id": "738124695",
        "access_token": "<VALID_USER_FACEBOOK_TOKEN_WITH_PUBLISH_ACTIONS_PERMISSIONS",
        "expiration_date": "1342683312"                
    }
};type=application/json' \
https://sample.com/api/posts

Facebook posting code :

public static void uploadToFB() {
    HttpClient client = getNewHttpClient();
    HttpPost httpost = new HttpPost("https://sample.com/api/posts");
    httpost.addHeader("image", "filename.png");
    httpost.addHeader("svgz", "filename.svgz");
    httpost.addHeader("type", "application/json");
    httpost.setHeader("Content-type", "application/json");
    JSONObject data = new JSONObject();
    JSONObject facebook = new JSONObject();
    JSONArray location = new JSONArray();
    HttpResponse response = null;
    try {
        data.put("text","Hello world!");
        data.put("templateid","0010");
        data.put("timestamp","2012-07-08 09:00:45.312195368+00:00");

        location.put(37.7793);
        location.put( -122.4192);
        data.put("location", location);
        facebook.put("id", "738124695");
        facebook.put("access_token", "AAADdF92joPABAKmRojBuXZAZAP"+
            "qF8ZAxM2bM"+
             "UnIErUSYZB85y5vIHAZDZD");
        facebook.put("expiration_date", "2013-07-07T 22:00:00Z");
        data.put("facebook", facebook);

        System.out.println(" ---- data ----- "+data);

        StringEntity stringEntity = new StringEntity(data.toString());
        httpost.setEntity(stringEntity);
        try {
            response = client.execute(httpost);
            System.out.println(" --- response --- "+response);
            HttpEntity entity = response.getEntity();
            // If the response does not enclose an entity, there is no need
            // to worry about connection release
            if(entity != null) {
                // A Simple Response Read
                InputStream instream = entity.getContent();
                String result = convertStreamToString(instream);
                System.out.println(" ---- result ---- "+result);

                // Closing the input stream will trigger connection release
                instream.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (JSONException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

It was an untrusted network, so, for that I did something like below as in this link.

private static HttpClient getNewHttpClient() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}
  • 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-18T02:26:57+00:00Added an answer on June 18, 2026 at 2:26 am

    After some hard time I got solution for my problem. Now, using MultipartEntity, I am able to send data to server like below.

        HttpClient httpClient = getHttpClient();
    
        HttpPost httpost = new HttpPost("https://sample.com/api/posts");
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile1 = new FileBody(new File("file.png"), "image/png");
        mpEntity.addPart("image", cbFile1);
    
        ContentBody cbFile2 = new FileBody(new File("file.svg"), "image/svg+xml");
        mpEntity.addPart("svgz", cbFile2);
    
        ContentBody cbFile3 = new StringBody(getJsonData().toString(), "application/json", Charset.forName("UTF-8"));
        mpEntity.addPart("json", cbFile3);
    
        httpost.setEntity(mpEntity);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to post login credentials to an https site using cURL
I'm trying to write a hard-coded HTTP Post request with SOAP action, using the
I am trying to make a Http POST request using apache HTTP client. I
I'm trying to post an array using a POST request to a specific page,
I'm getting an error when trying to execute the performSegueWithIdentifier method inside a setCompletionBlock
I'm trying to send a POST request to a PHP script (http://mywebsite/index/test/ in this
Trying to execute powershell script in my C# code. Using .NET Framework v. 4.0.30319
I'm trying to execute command prompt commands and read the output in C#. This
I'm trying to execute the following code, but I'm getting SyntaxError: invalid syntax at
Right now I'm using this code to upload files to Google Drive: https://stackoverflow.com/a/11657773/1715263 It

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.