Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The processing method of HTTP 302 in Linux curl command

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to deal with HTTP 302 in Linux curl command". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to deal with HTTP 302 in the Linux curl command.

When using the curl command on a Linux system, you occasionally encounter some URL jumping to the new URL, that is, 3XX in HTTP (redirection, redirection, such as HTTP 302).

$curl-s-I $URL > log

At this point, in the returned message, there is a Location field indicating the new URL.

$cat log HTTP/1.1 302 Found Expires:-1 Cache-Control: private, max-age=0Pragma: no-cache Location: http://182.118.2.11/youku/557186***52945820CFCE162719/03000811074CDDB614769602996C24421AE8D8-C2A3-1BD9-74AC-F5B071A94E33.MP4 Content-type: text/html Connection: close Date: Tue, 0***pr 2011 08:37:07 GMT Server: F_LIGHTY_TJ8

When I try to get this new URL and then curl it, I always report HTTP 400 (Bad Request, wrong request).

$URL= `cat log | grep'^ Location' | cut-f2-d '`$curl-s-I $URL > log $cat log HTTP/1.1 400 Bad RequestContent-Type: text/html Content-Length: 349 Connection: close Date: Tue, 0***pr 2011 08:32:04 GMT Server: YOUKU.ZZ

Print the new URL directly, copy and paste it, and then curl it, but there's no problem.

Curl-s-I http://182.118.2.11/youku/557186***52945820CFCE162719/03000811074CDDB614769602996C24421AE8D8-C2A3-1BD9-74AC-F5B071A94E33.MP4 HTTP/1.1 200 OK Content-Type: video/MP4 Accept-Ranges: bytes ETag: "392853628" Last-Modified: Fri, 12 Nov 2010 21:48:23 GMT Content-Length: 19971197 Connection: close Date: Tue, 0***pr 2011 08:41:18 GMT Server: YOUKU.ZZ

I don't understand!

***. It is found that the new $URL is not exactly the same as "http://182.118.2.11/youku/557186***52945820CFCE162719/03000811074CDDB614769602996C24421AE8D8-C2A3-1BD9-74AC-F5B071A94E33.MP4"," with an extra'0A 'line break at the end of $URl.

$echo $URL > url_1 $echo http://182.118.2.11/youku/557186***52945820CFCE162719/03000811074CDDB614769602996C24421AE8D8-C2A3-1BD9-74AC-F5B071A94E33.MP4 > url_2 $hexdump url_10000000 7468 7074 2f3a 312f 3238 312e 3831 322e0000010 312e 2f31 6f79 6b75 2f75 3935 3337 45380000020 3244 4637 3335 3831 4239 4144 43360000030 4533 3941 302f 3033 3030 3138 3031 34370000040 4443 4244 3136 3734 3936 3932 36390000050 243 33434 3132 4541 4438 2d38 3243 33410000060 312d 4442 2d39 34441 462d 4235 37000070 4131 3439 2e33 706d 0d34 000a$hexdump url_20000000 7468 7074 2f3a 312f 31238 3831 322e0000010 312e 2f31 6f79 6b75 2f75 3935 3337 45380000020 3244 4637 3335 3834 3831 4239 4144 43360000030 4533 3941 302f 3033 3030 3138 3031 34370000040 4443 4244 3136 3734 3936 3036 3932 36390000050 3243 3434 3132 4541 4438 2d38 3243 33410000060 312d 4442 2d39 3437 4341 462d 4235 37300000070 4131 3439 3345 2e33 706d 0a34

Get rid of this newline character, everything OK

URL= `cat log | grep'^ Location' | cut-f2-d''| sed's /\ r Been dazed and confused for so long. I believe you have a better understanding of "how to deal with HTTP 302 in the Linux curl command". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report