I want to use CURL to check if the server the REST API is hosted is UP or responding
I have a c#.NET REST API http://localhost:55223/api/Demo/PostData?
I want to check if the server that hosted REST api is reponding before i make a call to my REST service
I am using following way to check i wanted to know if it is the right way
There might be an issue with the url design here. Since, post data is always sent in the body and as a post request, whereas the URL and the request in the above example depicts a totally different scenario.
curl -XPOST -H "Content-type: application/json" -d 'Add body here or remove this text and -d flag' 'http://localhost:55223/api/Demo/Post'
This would totally suffice a correct request though you need to edit the -d flag within the command for your request.
script.sh
#!/bin/bash
CURL='/usr/bin/curl'
if CURL -XPOST -H "Content-type: application/json" -d 'Add body here or remove this text and -d flag' 'http://localhost:55223/api/Demo/PostData'
else
echo "Not Found"
fi
If you are trying to hit the API to test it, go through Postman to send out those requests.
Related
In google cloud storage I have a bucket with default storage class as standard. When I upload objects into this bucket, I need to set the storage class of some objects to coldline.
Is it possible to set the storage class during the upload? Or should I upload first and then change the storage class for the object. In the documentation I only found a way to change the storage class of an uploaded object.
According to the API documentation, yes it's possible. I don't know if the standard libraries (especially in c# because I don't know that language); but you can do that by API call (or implement this call in the language of your choice).
Be careful, you have to use a multipart upload to define that metadata when you upload the content.
With that multipart file content (multipart.json)
--BOUNDARY_STRING
Content-Type: application/json; charset=UTF-8
{"name": "myObject", "storageClass": "COLDLINE"}
--BOUNDARY_STRING
Content-Type: application/text
runtime: go116
instance_class: F4
--BOUNDARY_STRING--
Use that API call
curl -X POST --data-binary #multipart.json \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: multipart/related; boundary=BOUNDARY_STRING" \
-H "Content-Length: 221" \
-H "Storage-Class: COLDLINE" \
"https://storage.googleapis.com/upload/storage/v1/b/YOUR_BUCKET/o?uploadType=multipart"
(Change YOUR_BUCKET with a real bucket. It worked for me)
I wrote a curl example to use the rest api of "aws iot core" and confirmed that it was operating. However, in the authentication process in the c# http client, I do not know how to insert the following three authentication values.
I would appreciate it if I could get help.
Below is the curl phrase.
curl --tlsv1.2 --cacert AmazonRootCA1.txt \
--cert test_thing.cert.pem \
--key test_thing.private.key \
--request POST \
--data "test gogo" \
"https://[iot_url].iot.ap-northeast-2.amazonaws.com:8443/topics/topic_2?qos=1" \
I'm talking to a custom API, that will give me a file, if I send a GET request, with a body. And yes, I'm fully aware of how horrible that is, so please don't remind me.
I'm using Sockets to send the requests, and normally these GET requests return JSON data, which I can read just fine. However, I now need to download a file, and the socket keeps on closing. To be specific, I keep on getting this exception:
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
If I use curl to make the request, I get the file:
curl -d '{"thing" : "blah"}' -H "Content-Type: application/json" -X GET http://127.0.0.1:1337/api/0.1/test/download > test.zip
If I use fiddler, I get the file returned.
But C# sockets keep on throwing that exception. I don't have any code to show, as I really don't know the best way to handle the data transfer. But I've tried no end of loops, and nothing seems to be working. If anyone could provide some guidance on how to do this, I'd appreciate it.
Thanks
I am trying to use the new Facebook Messenger Platform API to send image message using image file from application directory.
Facebook gives the example using cURL like below:
curl \
-F recipient='{"id":"USER_ID"}' \
-F message='{"attachment":{"type":"image", "payload":{}}}' \
-F filedata=#/tmp/testpng.png \
"https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"
But I am trying to use the API with C#. For your information, I have successfully use the API if I use the file from an internet url.
I have tried to fill in the filedata property by using base64 string of the image file, but unsuccessful.
Kindly explain how does cURL works with the given file path especially image and create a POST request to the web server? And if possible, what options do I have to do it with C#?
The -F option is for form. This is equivalent to issuing a POST request with the Content-Type header of multipart/formdata and the request body containing all the key-value pairs listed with a proper boundary set. cURL will read the binary data and put the bytes in the correct boundary in the request. There are many examples online for C# to submit a multipart/formdata request. Look into HttpClient or WebClient file uploads and you'll find what you need.
I'll be away from a computer for a few days and submitting sample code from a mobile device isn't the easiest thing to do. If you need some sample code, let me know.
Does the JIRA SOAP API allow me to link betwen two issues that are in different projects? I have looked online and not found a way to do this. The closest thing that I have seen is the createIssueWithParent method, which creates subissues (I want two issues to be linked, not subissues) and which requires the issues to be in the same project (also not what I want).
Does anyone know of a way to do this?
No easy way in SOAP but I've done this using the RESTful approach and JIRA 4.4, e.g.
#
# Add links to JIRA issues
#
# Matt Doar
# CustomWare
#
# usage: create_links.sh issue_id issue_key
# where the issue_id is the unique id for a JIRA issue, not it's issue key.
# You can see the issue id in the XML view of an issue.
# and issue_key is the other issue to be linked to.
USERNAME=admin
PASSWORD=secret
SERVER_URL="http://localhost:8080"
DASHBOARD_PAGE_URL=$SERVER_URL/secure/Dashboard.jspa
COOKIE_FILE_LOCATION=jiracoookie
# Get the authentication cookie
curl -u $USERNAME:$PASSWORD --cookie-jar $COOKIE_FILE_LOCATION -sS --output /dev/null $DASHBOARD_PAGE_URL
issueid=$1
issuekey=$2
#echo "Linking issue: $issueid and $issuekey"
curl --cookie $COOKIE_FILE_LOCATION --header "X-Atlassian-Token: no-check" -sS --output /dev/null -d "id=$issueid" -d "linkDesc=relates to" -d "linkKey=$issuekey" "$SERVER_URL/secure/LinkExistingIssue.jspa"
rm -f $COOKIE_FILE_LOCATION
I don't think that linking is possible via the SOAP API. I've done this using the XML-RPC API, with the createIssueLink function:
from com.atlassian.jira import ComponentManager
# get issue objects
authenticationContext = ComponentManager.getInstance().getJiraAuthenticationContext()
issueLinkManager = ComponentManager.getInstance().getIssueLinkManager()
# Link parent issue to subtask
issueLinkManager.createIssueLink(issue.getId(),otherIssue.getId(),10003,1,authenticationContext.getUser())