Setting content-disposition free text using libcurl in multi post using curl_formadd - libcurl

How I can set content-disposition whole text using libcurl in multi post using curl_formadd
e.g
set this for one part in multi/part http post.
Content-Disposition: form-data; name="UploadFile" filename="text.zip"
Thanks,
Naeem

You cannot "set the whole text" using curl_formadd().
curl_formadd() just creates and adds a struct to a linked list of 'struct curl_httppost' structs, and that linked list is what passes instructions to libcurl. You can build and populate such a linked list yourself and then you can set the text to whatever you like.

Related

JMeter - How to extract values from a response which has been decoded from base64 and stored in a variable? All under the same sampler

I am trying to test a webservice's performance, and having a few issues with using and passing variables. There are multiple sequential requests, which depend on some data coming from a previous response. All requests need to be encoded to base64 and placed in a SOAP envelope namespace before sending it to the endpoint. It returns and encoded response which needs to be decoded to see the xml values which need to be used for the next request. What I have done so far is:
1) Beanshell preprocessor added to first sample to encode the payload which is called from a file.
2) Regex to pull the encoded response bit from whole response.
3) Beanshell post processor to decode the response and write to a file (just in case). I have stored the decoded response in a variable 'Output' and I know this works since it writes the response to file correctly.
4) After this, I have added 4 regex extractors and tried various things such as apply to different parts, check different fields, check JMeter variable etc. However, it doesn't seem to work.
This is what my tree is looking like.
JMeter Tree
I am storing the decoded response to 'Output' variable like this and it works since it's writing to file properly:
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
String Createresponse= vars.get("Createregex");
vars.put("response",new String(Base64.decodeBase64(Createresponse.getBytes("UTF-8"))));
Output = vars.get("response");
f = new FileOutputStream("filepath/Createresponse.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(Output);
f.close();
And this is how I using Regex after that, I have tried different options:
Regex settings
Unfortunately though, the regex is not picking up these values from 'Output' variable. I basically need them saved so i can use ${docID} in the payload file for next request.
Any help on this is appreciated! Also happy to provide more detail if needed.
EDIT:
I had a follow up question. I am trying to run this with multiple users. I have a field ${searchuser} in my payload xml file called in the pre-processor here.
The CSV Data set above it looks like this:
However, it is not picking up the values from CSV and substituting in the payload file. Any help is appreciated!
You have 2 problems with your Regular Expression Extractor configuration:
Apply to: needs to be response
Field to check: needs to be Body, Body as a Document is being used for binary file formants like PDF or Word.
By the way, you can do Base64 decoding and encoding using __base64Decode() and __base64Encode() functions available via JMeter Plugins. The plugins in their turn can be installed in one click using Plugin Manager

content type headers from multipart in django

I have a django endpoint that gets a multipart and I want look at the
content type headers in each part. When I look at
request.META['CONTENT_TYPE'] I get:
'multipart/form-data;
boundary="boundary_.oOo._OTEwMTc3NzM5ODMxMjQxNzkyMTI5OTY3NDQwOQ=="'
Googling this I found this multiparts parser but I cannot find any docs on how to use it and I can't figure out how to use it.
How can I get the content type headers from each part?

How to get the file-name before downloading the file

I am trying to download a binary file from a http: server. I am using the functions InternetOpenUrl() and then InternetReadFile() to download the file. Is it possible to know the file name before downloading?
What I am doing now to get the file name is- Once the download is complete, using GetFileVersionInfo() and from the buffer i am getting the OrginalFilename, then renaming the file to the OrginalFilename.
Is there any other way to get the file name before downloading?
Thanks
Vinod
Look at HttpQueryInfo. Look at the Content-Type and Content-Disposition headers.
You may have to use HTTP_QUERY_CUSTOM to get raw content-type if it just returns e.g. "text/plain".
To get all the headers (and thereby work out which one contains the information you want) you can use HTTP_QUERY_RAW_HEADERS_CRLF.

Is to possible to find filename from http headers

Usually when downloading files, suppose using QNetworkAccessManager, the filename is not present at the end of link. How to get proper file names in that case. Even if link doesn't contain a hint of name, firefox always downloads the file with its proper name and extension. We can get a hint of extention using mime-types but what about file names.
Yes. It's the Content-Disposition: attachment; filename=<file name.ext> header. There's a strong suggestion to set the content type to application/octet-stream so browsers and their plugins are not tempted to open it instead.

How to retrieve codepage from cURL HTTP response?

I'm using lib-cURL as a HTTP client to retrieve various pages (can be any URL for that matter).
Usually the data comes as a UTF-8 string and then I just call "MultiByteToWideChar" and it works well.
However, some web-pages still use code-page encoding and I see gibberish if i try to convert those pages to UTF-8.
Is there an easy way to retrieve the code page from the data? or I'll have to scan it manually (for "encoding=") and then translate it accordingly.
If so, how do i get the code-page id from name (Code Page Identifiers)?
Thanks,
Omer
There are several location where a document can state its encoding:
the Content-Type HTTP header
the (optional) XML declaration
the Content-Type meta tag inside the document header
for HTML5 documents the charset meta tag.
There are probably even more I've forgotten.
In the end, detecting the actual encoding is rather hard. You really shouldn't do this yourself but use high-level libraries for retrieving and parsing HTML content. I'm sure they are available even for C++, even if they have to be thiefed from the a browser environment. :)
I used DetectInputCodepage in IMultiLanguage2 interface and it worked great !