1
$\begingroup$

First I use

ClearCookies[All];
ck = URLRead @ HTTPRequest["https://wolfram.com",CookieFunction->Print]

to get an example of cookies. Then I save the cookie example to a variable and use

req = HTTPRequest["www.example.com",<|"Cookies"->{cookies}|>];
URLRead@req;

I both tried adding and not adding a {} to the cookies but they all have the same results. Website shows me "permission-denied" and acquire login. I'm trying to capture my browser identity cookies and use them in mathematica HTTPRequest function. I use Fiddler to find out what request is sent by MMA kernel.

Here is the record of Fiddler: enter image description here

As you can see, there is no cookies data sent in this request. I searched reference but not found examples for how to send requests with cookies data. Here is a request with normal cookies data from Edge. enter image description here

I'm quite confused about the cookies usages in mathematica, reference shows only cookies management but not telling how to sending them. Can someone tells me how to send requests with correct cookies data? I'm using these requests to access and dig some websites which need certification.

$\endgroup$
6
  • $\begingroup$ Your syntax is correct. It is hard to blindly debug why the site doesn't allow you the access. Providing cookies might not be enough though: Try adding other HTTP Headers and UserAgent to your HTTP request. $\endgroup$ Commented Aug 3, 2023 at 14:31
  • $\begingroup$ @Domen I know what you mean but at least once I send a request with only cookies data the traffic monitor software like Fiddler should capture the request which has only cookies data. If the software cannot detect cookies data nor the website could. So I'm quite sure just add headers or other payloads cannot solve the problem. Anyway, thanks for discussion. $\endgroup$ Commented Aug 5, 2023 at 10:41
  • 1
    $\begingroup$ @Schwarzer, I see now what you mean. I think HTTPRequest with cookies works fine. Please add your complete code that you are using (that is, include also the definition of cookies) so that we can use the same code and test it. And also include which Mathematica version you are using. $\endgroup$ Commented Aug 5, 2023 at 11:34
  • $\begingroup$ @Domen Thanks for keeping up with this, I'm now attaching the source code to the comments: ClearCookies[All]; ck = URLRead @ HTTPRequest["https://wolfram.com",CookieFunction->Print] cookies=ck["Cookies"] req = HTTPRequest["www.example.com",<|"Cookies"->{cookies}|>]; URLRead@req;. The result of my subsequent monitoring of the sent requests on fiddler is the image I attached in the question. My MMA version is 13.2. $\endgroup$ Commented Aug 7, 2023 at 12:01
  • 1
    $\begingroup$ How do you expect cookies with "Domain" set to "wolfram.com" to work on "example.com"? :) You have to correctly set/change the domain. $\endgroup$ Commented Aug 7, 2023 at 12:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.