每次我尝试为嵌入式项目获取Instagram API时,都会以“ 301永久移动”作为响应。因此,我将请求和端口中的HTTPS和HTTPS更改为443。现在其响应为2。
import socket as socks
handle = socks.socket(socks.AF_INET, socks.SOCK_STREAM)
ip = socks.gethostbyname('api.instagram.com')
request = "GET /v1/users/self/?access_token=6xxxxxx.3fxxxxxxxxxxxxxxxxxxx HTTPS/1.1\r\n"
request += "Host: api.instagram.com\r\n"
request += "Content-Type: application/json\r\n"
request += "Connection: close\r\n\r\n"
handle.connect((ip,443))
handle.send(request.encode())
result = handle.recv(4096)
print(ip)
print(result)
以下是输出:
blackfly@BlackFly:~$ python client.py
157.240.23.63
2