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" \
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'd like to leverage the new Google TTS using a simple rest request. To that end, I've created a Service Account which downloaded a JSON file containing a private key id, a private key, client email, client id, client_x509_cert_url, etc.
I've also set the environment variable for the system:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", jsonFile);
I then found this sample CURL request to use the WaveNet TTS engine provided by Google:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1beta1/text:synthesize" > writtenfile.txt
I want to create a simple C# webrequest from the above CURL request, but the line "gcloud auth application-default print-access-token" is a problem for me. I cannot install a CLI gcloud instance on this machine. Isn't there some way to setup the webrequest authorization access token from the JSON service account file? Surely I don't HAVE to have gcloud installed.
Looking for code sample demonstrating how to convert CURL code to a C# rest request using the service account json file without gcloud.
In case you don't want to install the gcloud packages, you can execute REST calls by using API Keys. These keys can be created directly in the GCP console and they can be passed as a parameter through the request header; in this way, you can authenticate to the service without the need of gcloud. Additionally, I suggest you to take a look on this guide that contains the steps required to make REST requests with C#.
You can use this Restlet Client tool to test the following example:
REST content Example
Header
https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=<YOUR_API_KEY>
Body
{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}
Finally, in case you want to consume a Service Account JSON file, you can use the Client libraries to create and send your TTS requests to then authenticate them directly from your code; however, this method require to install the TextToSpeech packages.
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.
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())