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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:48:24+00:00 2026-06-11T02:48:24+00:00

How I would write the following curl POST method using R and the RCurl

  • 0

How I would write the following curl POST method using R and the RCurl package?

curl -k -u myusername:mypassword -d '{"text":"Hello World!","level":"Noob"}' -H "Content-Type: application/json" -H "Accept: application/json" "http://api.website/v1/access?"
  • 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-11T02:48:26+00:00Added an answer on June 11, 2026 at 2:48 am

    FINAL EDIT: After emailing the great Duncan Temple Lang I have a solution:

    library(RCurl)
    library(RJSONIO)
    postForm("http://api.website/v1/access?",
             .opts = list(postfields = toJSON(list(text = "Hello World!", level = "Noob")),
                          httpheader = c('Content-Type' = 'application/json', Accept = 'application/json'),
                          userpwd = "Username:Password",
                          ssl.verifypeer = FALSE))
    

    My previous post is below but it has all now been superseded by the edit above (I’ve left the below for reference):

    I would like to know the answer to this question myself. even looking at TARehman’s answer I still can’t work out how to do it (my lack of understanding is no doubt the root).

    If you download curl from its website (I used the generic-win binary version), then here’s one way of doing it in R via the ‘system’ command which is like using the window’s command line window but from R:

    output <- system('C:/+/curl-7.27.0-rtmp-ssh2-ssl-sspi-zlib-idn-static-bin-w32/curl  -k -u "username:password" -d "{\\"text\\":\\"Hello World!\\",\\"level\\":\\"Noob\\"}" -H "Content-Type: application/json" -H "Accept: application/json" "http://api.website/v1/access?"', intern = TRUE))
    

    The above works with one of the API’s I use. You can then use

    I really hope you find an answer because it would be useful for me to know too.

    EDIT: My attempt using an actual API with RCurl via @TARehman’s example:

    Here is the curl code which works fine:

    x = system('C:/+/curl-7.27.0-rtmp-ssh2-ssl-sspi-zlib-idn-static-bin-w32/curl  -k -u "USERNAME:PASSWORD" -d "{\\"text\\":\\"Have a nice day!\\"}" -H "Content-Type: application/json" -H "Accept: application/json" "http://api.theysay.io:60000/v1/sentiment?"', intern = TRUE)
    

    And here is how I’ve rewritten it in RCurl:

    curl.opts <- list(userpwd = "username:password", 
                      httpheader = "Content-Type: application/json",
                      httpheader = "Accept: application/json",
                      timeout = 20, 
                      connecttimeout = 20, 
                      verbose = TRUE, 
                      useragent = "RCurl",
                      cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
    
    postForm("http://api.theysay.io:60000/v1/sentiment?", .params = c(data = '{\\"text\\":\\"Have a nice day!\\"}'), .opts = curl.opts)
    

    This however did not work and results in the following (clearly I have not understood something correctly):

    * About to connect() to api.theysay.io port 60000 (#0)
    *   Trying 163.1.94.100... * connected
    * Connected to api.theysay.io (163.1.94.100) port 60000 (#0)
    > POST /v1/sentiment? HTTP/1.1
    User-Agent: RCurl
    Host: api.theysay.io:60000
    Accept: application/json
    Content-Length: 193
    Expect: 100-continue
    Content-Type: multipart/form-data; boundary=----------------------------7620b19c7a5d
    
    < HTTP/1.1 100 Continue
    < HTTP/1.1 401 Unauthorized
    < WWW-Authenticate: Basic realm="Secured Resource"
    < Content-Type: text/plain
    < Server: spray-can/1.0-M2.1
    < Date: Wed, 12 Sep 2012 12:26:06 GMT
    < Content-Length: 77
    < 
    * Ignoring the response-body
    * Connection #0 to host api.theysay.io left intact
    * Issue another request to this URL: 'http://api.theysay.io:60000/v1/sentiment?'
    * Re-using existing connection! (#0) with host api.theysay.io
    * Connected to api.theysay.io (163.1.94.100) port 60000 (#0)
    * Server auth using Basic with user '[USERNAME]'
    > POST /v1/sentiment? HTTP/1.1
    Authorization: Basic [KEY]==
    User-Agent: RCurl
    Host: api.theysay.io:60000
    Accept: application/json
    Content-Length: 193
    Expect: 100-continue
    Content-Type: multipart/form-data; boundary=----------------------------949d191bdaeb
    
    < HTTP/1.1 100 Continue
    < HTTP/1.1 415 Unsupported Media Type
    < Content-Type: text/plain
    < Server: spray-can/1.0-M2.1
    < Date: Wed, 12 Sep 2012 12:26:06 GMT
    < Content-Length: 93
    < 
    * Connection #0 to host api.theysay.io left intact
    [1] "There was a problem with the requests Content-Type:\nExpected 'text/xml' or 'application/json'"
    attr(,"Content-Type")
    
    "text/plain" 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I write the following query using Linq to SQL? UPDATE [TB_EXAMPLE] SET
How would I properly write the following INSERT using LIKE? provider = provider cursor.execute(INSERT
How would I write the following for loop using an enhanced for loop> int
Using MySQL syntax, how would I write a query to return the following (I
How would I write the following C# code in F#? namespace Shared { public
I would like to write the following SQL in HQL so it executes as
The following is for Python 3.2.3. I would like to write a function that
I am trying to write a very thin hypervisor that would have the following
I have basic authentatication working with REST API using curl: curl -X POST -H
How would you write the following in Microsoft SQL Server 2008? IF EXISTS(SELECT *

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.