How to set Content-Type in a webrequest
How do I set the Content-Type in header of the WebRequest Task?
The header is type of WebHeaderCollection. But this is a Read Only class. Header properties i ussely set by the WebRequest class.
in GeoCortex Workflowmanager the tooltip say that the header can be set as KeyValuedPairs, But how to do that in text?
-
Hi Sebastian,
(https://data.latitudegeo.com/community/WorkflowSamples/webrequestwithheaders.xaml) This workflow provides an example of assigning headers to a WebRequest activity.
It is a little awkward because you need to use the InvokeMethod activity to do this but it is possible. Have a look at the Parameters collection of the two InvokeMethod activities. You can use Fiddler to verify that the assigned headers are sent.
--Ryan
0 -
Hi Ryan
Your example worked fine, but if I try to set the Content-Type to "application/json" in a POST request i got this error
"The Content-Type header cannot be changed from its default value for this request."
0 -
Hi Sebastian,
I can see the issue you are having now. I'm not sure if there is a way to get the Web Request activity to do exactly what you want here. This activity takes a list of parameters that are name/value pairs and includes them as the data for the request. By making a web request with name/value pairs we are basically requiring that the content type is "application/x-www-form-urlencoded". In your case it sounds like you need to POST a JSON string to the URL. This activity doesn't provide a way for you to supply the entire payload for the request.
--Ryan
0 -
Hi Sebastian,
I've cooked up a C# Script activity that does this: (https://data.latitudegeo.com/community/WorkflowSamples/webrequest_addfeatures.xaml) w (https://data.latitudegeo.com/community/WorkflowSamples/webrequestwithheaders2.xaml) ebrequestwithheaders2.xaml
This isn't the first time we've encountered the need to make a "raw" web request. I'll file a new feature request to cover this.
--Ryan
0 -
Thanks. It's seem to do the trick./customer/servlet/servlet.FileDownload?file=00P6000000e87wBEAQ
0 -
Hi Geoff
You can see here how serialize objects to JSON
Then convert the json string to byte array
Encoding.UTF8.GetBytes(JSON)
then use the C# script providet by Ryan and that should be it :-)
0 -
Hi Geoff,
The workflow you included isn't far off. The problem is that the format of the "features" parameter of the Web Request activity was incorrect. See this working example that submits an "add features" request to our demo server (https://data.latitudegeo.com/community/WorkflowSamples/webrequest_addfeatures.xaml) webrequest_addfeatures.xaml . You can run this completely in the workflow simulator.
Since the ArcGIS Server FeatureLayer/addFeatures endpoint accepts URL/Form parameters there is no need to set the content type of the Web Request activity.
Also, this very same task can be performed with the "Add Features" activity. It allows you to provide the features to add as a FeatureSet object, rather than manually assembling the JSON for them.
--Ryan
0 -
@Sebastian,
As of Essentials 3.15 the Web Request activity supports the ability to make a raw web requests with arbitrary data and content-types. I've rewritten the previous C# Script example to do this (https://data.latitudegeo.com/community/WorkflowSamples/ webrequestwithheaders3.xaml) webrequestwithheaders3.xaml . You'll see that the "Raw Data" and "Headers" arguments of the Web Request activity now get assigned.
--Ryan
0 -
I've used this information to do some "ApplyEdits" to a table too using GC 3.14. You just have to write the right formatting using the "updates" parameter i.e.: "[{""attributes"":{""OBJECTID"":" + RelatedRowNumberStr + ",""" + FieldName2EditStr + """:""" + NewTextStr + """}}]". The Uri has to look like ..../featureServer/1/applyEdits and f has to be "json" or "pjson"
0 -
@Ryan, 0 -
Hello 0 -
Hi Phil, 0 -
I've rehosted Ryan's workflows and corrected the links. 0 -
Hi Phil, 0 -
Thanks all - got this working... 0 -
Ryan, FYI, the link to webrequestwithheaders3.xaml above has a space just before the workflow name. The link returns a 404. Also, webrequestwithheaders2.xaml and webrequestwithheaders3.xaml do not work as written. The site used returns error: (401) Unauthorized. 0 -
Ryan, 0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
17 Kommentare