Specify Content Type For Each Part Of A Multipart Form Request - multipartform-data

I would like to be able to specify the content type for each part of a multipart form request individually, as specified by RFC 2388 section 3. (https://www.ietf.org/rfc/rfc2388.txt)
For example, in cURL, one can invoke the command
curl -v -X POST http://myserver.com/v1/form-data
-F 'request={"hello":"world"};type=application/json'
It was noted last year that many people have requested this, and the feature would be considered for implementation in a future release:
https://stackoverflow.com/a/38529839/4521962
Please reconsider this feature request, as it is a requirement for a number of contemporary REST API's.

Related

How to change configuration GTSon (i.e. for individual node have different GTS request) at command line in Castalia 3.3 Simulator?

I'm executing BANtest experiment provided in simulation example in Castalia 3.3 simulator. I'm exploring GTS in Contention Free Period (CFP) under beacon enable mode of IEEE 802.15.4 MAC. I want to change the configuration i.e. GTSon such a way that each individual node requests different GTS slots at command line. What do i need to change in configuration file ?
I read and understand the procedure to change configuration at command line from "section 3.5.3" at castalia user's manual. Currently, i'm able to change "equal" GTS request made by nodes in GTSon configuration at command line, but i am interested to get different GTS slots request form individual node.
Case-1: code for equal GTS request form all nodes
# Define as set of equal GTS request for all nodes in omnetpp.ini
[Config GTSon]
SN.node[*].Communication.MAC.requestGTS = ${GTS=1,2}
# Execute BANtest example- take request GTS from config file
$ Castalia -c ZigBeeMAC,[GTSon]
# Changing configuration (i.e. GTSon) form command line-run successfully
$ Castalia -c GTSon=\$\{GTS=0,3\}
Case-2: code for different GTS requests form nodes
# Define differnt GTS requests for nodes in omnetpp.ini
[Config GTSon]
SN.node[1].Communication.MAC.requestGTS = ${GTS1=0}
SN.node[2].Communication.MAC.requestGTS = ${GTS2=4}
SN.node[3].Communication.MAC.requestGTS = ${GTS3=3}
SN.node[4].Communication.MAC.requestGTS = ${GTS4=0}
SN.node[5].Communication.MAC.requestGTS = ${GTS5=0}
# Execute BANtest example- run successfully
$ Castalia -c ZigBeeMAC,[GTSon]
# Changing configuration (i.e.GTSon) form command line- showing error
$ Castalia -c GTSon=\$\{GTS1=0,GTS2=1,GTS3=5,GTS4=0,GTS5=0\}
The case-1 is running successfully, but case-2 have error,which is given below:
"ERROR: configuration 'GTSon' has more than one parameter and cannot be used with '=' syntax"
The error you are getting is simply a limitation of the Castalia script. Castalia's User manual is explicit about this limitation in section 3.5.3. You can also search for this string: has more than one parameter and cannot be used with '=' syntax" in the Castalia script to find out more details, or to think about how you could extend it to support multiple cmdline parameters per configuration.
But an extension of functionality is not really needed. One simple workaround would be to define individual configurations for each node. For example
[Config GTSon-n1]
SN.node[1].Communication.MAC.requestGTS = ${GTS1=0}
[Config GTSon-n2]
SN.node[2].Communication.MAC.requestGTS = ${GTS2=4}
...
Then you can use Castalia to run
$ Castalia -c ZigBeeMAC,GTSon-n1,GTSon-n2
Or change the parameter in the cmdline
$ Castalia -c ZigBeeMAC,GTSon-n1=3,GTSon-n2=5
In general, I'd like to suggest that changing the simulation parameters at command line is not a good idea (at least for your regular simulations). You should only use this feature to run throwaway exploratory simulations, where you quickly want to test the effect of a change, without having to edit the ini file. The added bonus here is that the command line is saved with the output file so you have some trace of how this output file was produced. That's why this feature was added in Castalia. However, for your regular simulations studies, you should have the parameter values (or range of values) in the ini file itself. In this way there is a proper record of what the simulation study is supposed to be. OMNeT++ ini files are quite versatile, and you can achieve a lot of with their syntax. Make sure you know about all that OMNeT has to offer by reading chapter 9 of the OMNeT++ 4.x manual.

Slack - How to upload a file with a mode other than snippet through API

I am attempting to load files to a slack channel automatically from a server via the API, but I'm running up against the 1MB limit for snippets. Is there a way to use file.upload to post files as either hosted or post?
Here's the curl command I'm testing with:
curl -F file=$FILE_PATH -F channels=$CHANNEL_ID \
-F token=$TOKEN -F filename=$SLACK_FILE_NAME \
$SLACK ADDRESS -x $PROXY_SERVER
This successfully posts the file to the channel, but the mode is snippet which means it's not a particularly elegant looking interface in slack and subject to the very small 1MB limit.
EDIT:
When posting the file through the API here is the response that I am getting back (with potentially sensitive information sanitized):
{"ok":true,
"file":{"id":ID_NBR,
"created":1529417913,
"timestamp":1529417913,
"name":FILE_NAME,
"title":FILE_TITLE,
"mimetype":"text\/csv",
"filetype":"csv",
"pretty_type":"CSV",
"user":USER_ID,
"editable":true,
"size":74810,
"mode":"snippet", ###### This is where I see the mode snippet through APIs, in channel it appears as a snippet as well ######
"is_external":false,
"external_type":"",
"is_public":true,
"public_url_shared":false,
"display_as_bot":false,"username":"",
"url_private":URL,
"url_private_download":URL,
"permalink":URL,
"permalink_public":URL,
"edit_link":URL,
"preview":FILE_DATA,
"preview_highlight":"<div class=\"CodeMirror cm-s-default CodeMirrorServer\" oncopy=\"if(event.clipboardData){event.clipboardData.setData('text\/plain',window.getSelection().toString().replace(\/\\u200b\/g,''));event.preventDefault();event.stopPropagation();}\">\n<div class=\"CodeMirror-code\">\n<div><pre>FILE_DATA<\/pre><\/div>\n<\/div>\n<\/div>\n",
"lines":202,
"lines_more":201,
"preview_is_truncated":true,
"channels":[CHANNEL_IDS],
"groups":[],
"ims":[],
"comments_count":0}}

Incorrect lmstat stats while using flexlm's lmstat utility

I have been using flexlm's lmstat utility to get the license statistics on every 5min basis and so far i have observed that incorrect lmstat numbers on installed license counts and reservation counts as well! and such events occurs very intermittently :( we tried to upgrading lmstat and other stuffs like vendor daemons and so on! but nothing really helping
Can any one had this similar situation and good solution ?
It's hard to give you a response like 'you must do that' because there is no technical informations.
I try to propose you some ideas.
The lmutil lmstat command give a standard information. The problem is that the interpretation of the result is depending of the editor's license file, not from Flexnet.
For Matlab, you can have Name Networked User (NNU) and Concurent (CN) licenses. For the NNU, you have a login attached a each token. For CN, 'first arrived, first served'. If on the same server you have 10 NNU tokens and 10 CN token, lmstat -c <port#server> -a will report 30 tokens available.
It's only due to Mathworks. When you have 1 NNU token, you can use Matlab from 2 different hosts. So 10 NNU give 2 * 10 = 20 tokens, with the 10 CN tokens, it seems that you have 30 tokens. Very confusing for the users.
When you make a reservation, you consume the token when the license service start even if no one use the token. The number of available tokens is reduced.
[Update]
About of the version of 'lmgrd/lmutil', each vendor define a version to use, but often you can use a higher version.
I've checked Cadence, Comsol and other license services. The counts are good.
You must verify the counts for the lines like :
Users of <an increment>: (Total of 5 licenses issued; Total of 4 licenses in use)
After, you have the used token ('reserved' token are seen like 'used') :
1 RESERVATIONs for GROUP Better_Group (server/2700)
jason abc057 abc057 (v2015.0623) (shoe/28512 3886), start Fri 11/20 14:41
simon abc057 abc057 (v2014.1110) (shoe/28512 4166), start Fri 11/20 15:37, 2 licenses
When you manually check the count and if it is good, your license server is good. In the example : 2 real users but 3 tokens + 1 reservation = 4 token used. Be careful in your parsing, don't miss the , 2 licenses, I have a Awk script that miss that.
You must check in the same time the status of your license server, the logfile and the user's actions. To check the status, you can use :
lmutil lmstat -c <port>#<server> -a
When and how long a token is used is an software's property :
a token can be taken (OUT) when the software start and released (IN) when the software is stopped;
a token can be taken (OUT) only when a feature is called and released when the feature has finish his work;
a token can be taken (OUT) and released (IN) immediately to check if the software or the feature could be used.
So, if you check your licenses every fives minutes, many 'OUT' and 'IN' actions could be missing. But it's not a problem lmutil lmstat give only informations on the licenses at a specific instant.
If you want follow all usages, you must work with the logfiles like PHPlicensewatcher : http://phplicensewatch.sourceforge.net/. The tool make a 'scp' in a crontab to get the logfile on the licenses server.
Depending of the daemon vendor, when you update the license file, you could make a lmutil lmreread -c <file>, but some (like Matlab) don't accept this and you must make a restart. This could introduce a difference between the number of increments/tokens on the server and the resources available seen by a lmstat lmstatus -c <port#server> -i.

POST JSON to url using CURL and C

I'm tring to POST JSON data to a url from bash using:
$ curl -v -d '{xxx:200}&apikey=xxxxx' -X POST http://localhost/xxxx/input/post.json -H "Accept: application/json" -H "Content-Type:application/json"
And in C using the following:
int main(void)
{
CURL *easyhandle;
curl_global_init(CURL_GLOBAL_ALL);
easyhandle = curl_easy_init();
if(easyhandle) {
char *data="json={xxx:200}&apikey=xxxxx";
curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(easyhandle, CURLOPT_URL, "http://localhost/xxxx/input/post.json");
curl_easy_perform(easyhandle);
curl_easy_cleanup (easyhandle);
}
curl_global_cleanup();
return 0;
}
This is what i'm trying to achieve actually:
http://localhost/xxxx/input/post.json?json={xxx:200}&apikey=xxxxx
It doesn't seem to work. :(
I'm a complete novice to curl. Please help.
Thanks!
Fortunately the server I was sending the data handled POST and GET requests, so the code in question would suffice.
Others with a similar problem can use a simple workaround (If your code doesn't have real time constraints and is not performance intensive). You may fork a bash process using system() from C. This avoids you the trouble of encoding.
What you are trying to do is not performing a POST request but performing a GET request. However, I'm not sure this is a good idea, since GET parameters are limited in length (to something like 2 kB or so), and - as others have already mentioned - they need to be encoded and decoded and all the funky stuff which is a pain in the neck.
The URL pointing to localhost suggests me that you have control over the server code. If you used the POST parameters instead of the GET ones, you could use your current code as-is (which sets the POST body of the request, which is probably the right thing to do -- so you don't have to change your client code, you only have to change the server code.)

C program to convert Dollar to Rupee

Is there a way to write a C program to convert say Dollar to Indian Rupee (or visa-versa). The conversion parameter should not be hard coded but dynamic. More preciously it should get the latest value of Rupee vs Dollar automatically(from Internet) ?
Step 1 would be to get the latest conversion rate. You can use a web-service for that. There are many available. You can try this.
Request:
GET /CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD HTTP/1.1
Host: www.webservicex.net
Response:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">SOME_RATE_IN_DOUBLE</double>
For sending the request you can make use of cURL.
Once you have the response, just parse it to get the rate. Once you've the rate you can easily write the program to convert.
EDIT:
If using cURL is something you are not comfortable with you can make use of good old system and wget. For this you need to construct the URL first like:
www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD
then from the C program you can do:
char cmd[200];
char URL[] = "www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD";
sprintf(cmd,"wget -O result.html '%s'",URL); // ensure the URL is in quotes.
system(cmd);
After this the conversion rate is in the file result.html as XML. Just open it and parse it.
If you are using windows, you need to install wget for windows if you don't have it. You can get it here.
First, you need to find a server that can provides the conversion rate. After that, you write your program to fetch the rates from that server and use those information further in your program.
This site, http://www.csharphelp.com/2007/01/currency-converter-server-with-c/ although provides a tutorial for C# + Web, it can give you a general technical idea of how to do it.

Resources