java亚马逊模拟登录,编程方式登录到亚马逊用C#

I want to login to Amazon seller central programatically with C#. I don't want to use Amazon Web Services.

Here is what I have done so far:

private void button1_Click(object sender, EventArgs e)

{

string appURL = "https://sellercentral.amazon.com/gp/sign-in/sign-in.html/ref=xx_login_lgin_home";

string strPostData = "protocol=https&action=sign-in&email=test%40gmail.com&destination=https%3A%2F%2Fsellercentral.amazon.com%2Fgp%2Fhomepage.html%3Fie%3DUTF8%26%252AVersion%252A%3D1%26%252Aentries%252A%3D0&optin=1&ouid=01&password=ntest&sign-in-button=&metadata1=SIsVVcIUMA1uElSK%2BySsVuCX1YuhcTji35ShGdQ%2Fd4ipBgkh6qW6HcPfyVu4dbOFdZiErWz%2F9OumR%2FfeVnrNSUUSEkIokrMPxYFPtZTlfJc44D8hWHpewjOs5TF4NIDyehvkc5eHJ8GsDbiUSdBtOq4iBnIpkIpAodIzIVFHK%2FQJJICA9n%2F8abB4XfwODJrI7YSa1gwCMrJbh0wvpAW5%2B%2BHecdjA5Bin8slkBqj9LQG%2FfSrTXlAGPsW21qV2ba4kej5xdjytVTELVqnLPB9Fc1Z%2FR98qDpBkQ%2F2lM3EV4POoe0nsAMALomqvOhOkIInqp14Ic%2BxJU35hX89rIhmSQMpL1WtMGE%2F9A2ebmHV%2BzlW0tUZIfxyupg2MiNJIeg1uNqBhBT8duYyKp0n3d5gYOnhxYCQTqR297AV%2FDAdHSlbrJRT5HX9spg9RyHSTDLiGvhy1BaK0LIzvR%2Bj786i4Z%2FCGBpb31XcXrFx9uDe8rxtNRLFiDXqxUCCf8hTBEhtyYriB2%2FlZAvoIRyAZMLDYykncALiRVPOWkQX%2FQjZUu6M6bBfqaQ6ODQlbc0j9V2FZ%2BEQng456mQmUOoO5";

// Setup the HTTP request.

HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(appURL);

objWebRequest.Method = "POST";

objWebRequest.AllowAutoRedirect = true;

objWebRequest.CookieContainer = new CookieContainer(); //Enable Coolkie

objWebRequest.ContentLength = strPostData.Length;

objWebRequest.ContentType = "application/x-www-form-urlencoded";

objWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";

// Post to the login form.

StreamWriter swRequestWriter = new

StreamWriter(objWebRequest.GetRequestStream());

swRequestWriter.Write(strPostData);

swRequestWriter.Close();

// Get the response.

HttpWebResponse objWebResponse =

(HttpWebResponse)objWebRequest.GetResponse();

// Read the response

StreamReader srResponseReader = new

StreamReader(objWebResponse.GetResponseStream());

string strResponseData = srResponseReader.ReadToEnd();

srResponseReader.Close();

// Display the response.

webBrowser1.DocumentText = strResponseData;

}

}

When i execute it I get as a response the login page and don't login... Why? What I am doing wrong? I use to display the html response a web browser.

My goal is to login and then search some products in my inventory in seller central. How to do this and keep sessions and cookies on other webrequests i will do?

解决方案

They [Amazon] have numerous Javascripts on the page. The whole purpose of these scripts seems to be to prevent people doing what you are trying to do.

The manipulate the form data and call various other page assets. Amazon then use those other assets calls and the manipulated data to determine if the request is from a legitimate browser or something trying to emulate a browser.

It's a security measure to stop seller accounts being capable of a brute-force hack attack, etc.

The JS snippets are purposefully obfuscated to prevent you from easily reverse engineering them, but of course nothing is impossible when you apply knowledge, patience and tenacity.

If you want to pursue this then I would recommend reverse engineering the JS on the page and then emulate what those pieces if code do with the form values, etc. and also emulate the other asset calls, along with relative timing flow. Pay attention to cookies being secretly set in image or remote script headers, and ensure your cookie jar for your script is always behaving properly.

These anti-emulation techniques are used regularly to prevent bot networks from emulating clicks on PPC networks. They are not fool proof nor are they unbreakable, but it will take you considerable time to get it working.

Honestly, if your not happy with the programming styles or functionality of C# libraries they provide, then you may be best building your own library to utilise the Amazon Marketplace Web Services.

In the long run you'll have a much more stable toolkit that wont need updating regularly.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好,实现文件流上传到亚马逊S3对象存储可以使用Java SDK提供的TransferManager类来实现。下面是实现的步骤: 1. 引入依赖: ```xml <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-s3</artifactId> <version>1.11.973</version> </dependency> ``` 2. 创建S3Client对象: ```java AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withRegion(Regions.US_EAST_1) .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))) .build(); ``` 3. 创建TransferManager对象: ```java TransferManager transferManager = TransferManagerBuilder.standard() .withS3Client(s3Client) .build(); ``` 4. 创建Upload对象并开始上传: ```java File file = new File("your-file-path"); Upload upload = transferManager.upload(bucketName, objectKey, file); try { upload.waitForCompletion(); } catch (InterruptedException e) { e.printStackTrace(); } ``` 其中,bucketName为存储桶名称,objectKey为上传到S3的对象名称,file为要上传的文件。 如果想要实现文件流上传,可以将文件流转换为InputStream对象,然后使用TransferManager的upload方法上传: ```java InputStream inputStream = new FileInputStream(file); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(file.length()); Upload upload = transferManager.upload(bucketName, objectKey, inputStream, metadata); try { upload.waitForCompletion(); } catch (InterruptedException e) { e.printStackTrace(); } ``` 这样就可以实现文件流上传到亚马逊S3对象存储了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值