<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>api Archives - ZepiWolf.se</title>
	<atom:link href="https://zepiwolf.se/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>https://zepiwolf.se/tag/api/</link>
	<description>Furry Apps</description>
	<lastBuildDate>Mon, 15 Jul 2019 13:55:35 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://zepiwolf.se/wp-content/uploads/2019/05/cropped-logo512-32x32.png</url>
	<title>api Archives - ZepiWolf.se</title>
	<link>https://zepiwolf.se/tag/api/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Accessing the e621 API when it gets blocked by Cloudflare&#8217;s DDoS protection</title>
		<link>https://zepiwolf.se/2019/07/15/accessing-the-e621-api-when-it-gets-blocked-by-cloudflares-ddos-protection/</link>
					<comments>https://zepiwolf.se/2019/07/15/accessing-the-e621-api-when-it-gets-blocked-by-cloudflares-ddos-protection/#comments</comments>
		
		<dc:creator><![CDATA[ZepiWolf]]></dc:creator>
		<pubDate>Mon, 15 Jul 2019 12:58:22 +0000</pubDate>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[Cloudflare]]></category>
		<category><![CDATA[ddos protection]]></category>
		<category><![CDATA[e621 api]]></category>
		<category><![CDATA[e621 app]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[tws]]></category>
		<guid isPermaLink="false">http://zepiwolf.se/?p=296</guid>

					<description><![CDATA[<p>Here is a small tutorial on how to access the e621 API when it gets blocked by Cloudflare, as done in TWS. The code is in Java (for Android) but the basic principle should be the same for other languages. Starting from the beginning, the API returns an HTTP status code of 403 (forbidden) or <a class="read-more" href="https://zepiwolf.se/2019/07/15/accessing-the-e621-api-when-it-gets-blocked-by-cloudflares-ddos-protection/">READ MORE</a></p>
<p>The post <a href="https://zepiwolf.se/2019/07/15/accessing-the-e621-api-when-it-gets-blocked-by-cloudflares-ddos-protection/">Accessing the e621 API when it gets blocked by Cloudflare&#8217;s DDoS protection</a> appeared first on <a href="https://zepiwolf.se">ZepiWolf.se</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Here is a small tutorial on how to access the <a href="https://e621.net/help/show/api/" target="_blank" rel="noreferrer noopener" aria-label="e621 API (opens in a new tab)">e621 API</a> when it gets blocked by Cloudflare, as done in <a href="http://zepiwolf.se/dev/tws/">TWS</a>. The code is in Java (for Android) but the basic principle should be the same for other languages. </p>



<p class="wp-block-paragraph">Starting from the beginning, the API returns an HTTP status code of <strong>403</strong> (forbidden) or <strong>503</strong> (service unavailable) when Cloudflare blocks the API call. To access e621 and the API, a captcha must be completed. The simplest way is to use a <a rel="noreferrer noopener" aria-label="WebView (opens in a new tab)" href="https://developer.android.com/reference/android/webkit/WebView" target="_blank">WebView</a>: </p>



<script src="https://gist.github.com/ZepiWolf/eac31f4255dcf056a315e37f1bc38c60.js"></script>



<p class="wp-block-paragraph">where <strong>USER_AGENT</strong> is the exact same as in all other requests to the e621 API. This is important so that Cloudflare knows that it is the same client connecting. </p>



<p class="wp-block-paragraph">After completing the captcha Cloudflare redirects to e621, and the next step is to extract and store three cookies from the WebView. These are <strong>__cfduid</strong>, <strong>e621</strong> and <strong>cf_clearance</strong>. Two of these tells Cloudflare that the captcha has been completed and the third is an identifier for e621. Together, these can be used to bypass Cloudflare and make the API working again. </p>



<p class="wp-block-paragraph"><a rel="noreferrer noopener" aria-label="CookieManager (opens in a new tab)" href="https://developer.android.com/reference/android/webkit/CookieManager" target="_blank">CookieManager</a> extracts the cookies:</p>



<script src="https://gist.github.com/ZepiWolf/fe57e9101667d30a6f289ce04d28f41e.js"></script>



<p class="wp-block-paragraph">Save the values of these cookies in e.g. <a rel="noreferrer noopener" aria-label="SharedPreferences (opens in a new tab)" href="https://developer.android.com/reference/android/content/SharedPreferences" target="_blank">SharedPreferences</a>. The last step is to include the three cookies in all following API calls. An example using <a rel="noreferrer noopener" aria-label="Jsoup (opens in a new tab)" href="https://jsoup.org/" target="_blank">Jsoup</a>:</p>



<script src="https://gist.github.com/ZepiWolf/08a30847a7bca05b40ccde4e3de79496.js"></script>



<p class="wp-block-paragraph">Include the cookies and use the same user agent at all times and Cloudflare will not block the API calls to e621 :) (until you have to complete a captcha again)</p>
<p>The post <a href="https://zepiwolf.se/2019/07/15/accessing-the-e621-api-when-it-gets-blocked-by-cloudflares-ddos-protection/">Accessing the e621 API when it gets blocked by Cloudflare&#8217;s DDoS protection</a> appeared first on <a href="https://zepiwolf.se">ZepiWolf.se</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zepiwolf.se/2019/07/15/accessing-the-e621-api-when-it-gets-blocked-by-cloudflares-ddos-protection/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
