"You broke Reddit" when submitting new story - objective-c

I am making a Reddit app for the iPhone, and part of the app's functionality requires posting new stories (i.e. links or text) to Reddit.
When I attempt this, I make the following request and set the request's cookie based on a past login attempt:
http://www.reddit.com/api/submit/?uh=%#&text=TestofAPISubmitonapigee&kind=self&sr=redditdev&title=APISubmitTest&r=redditdev&api_type=json
(where %# is replaced by the user modhash, something along the lines of aa4aaaa3aaaaaa88ea8b19639c389521a813d21cb3e5688dbf)
Upon submitting the request, however, I receive this response:
<html>
<head>
<title>reddit broke!</title>
</head>
<body>
<div style="margin: auto; text-align: center">
<p>
<a href="/">
<img border="0" src="http://www.redditstatic.com/youbrokeit1.png" alt="you broke reddit" />
</a>
</p>
<p>
I've made a huge mistake!
</p>
</body>
</html>
Or a variation on the above message. Any thoughts on what I'm doing wrong?

I figured it out. All you have to do is put the POST data in the HTTP body of the NSMutableURLRequest using [request setHTTPBody:#"NSString of the POST data"]; rather than the above, which is technically a GET request. I found this confusing, since this method worked for logging in to Reddit using the API. It turns out that you can login by GETting, but you must POST to share a new link.

Related

upload values with webclient

im trying to upload to this form with vb.net
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/css/login.css">
</head><meta charset="UTF-8">
<form method="post" action="/addData">
<input type="text" name="id"/>
<textarea name="data"></textarea>
<input type="submit" name="add" value="go"/>
</form>
and here is the vb code
Dim data2 As New System.Collections.Specialized.NameValueCollection()
data2.Add("id", TextBox1.Text)
data2.Add("data", TextBox2.Text)
data2.Add("add", "go")
Dim client As New System.Net.WebClient
client.UploadValues("link", data2)
any idea what im doing wrong here?
im always getting error 404, but it's not right.
because i did simple check by showing msgbox displaying the page source.
and it worked
We can't say much from that (at least I can't).
What you should do is inspect the POST request you send (via your regular browser) that way you will know what you need to send.
For example, here is how the POST request looks like for posting this answer.
qualityBanWarningShown=false&referrer=https%3A%2F%2Fstackoverflow.com%2Fquestions%2Ftagged%2Fvb.net&post-text=We+can't+say+much+from+that+(at+least+I+can't).%0D%0A%0D%0AWhat+you+should+do+is+inspect+the+POST+request+you+send+(via+your+regular+browser)+that+way+you+will+know+what+you+need+to+send.&fkey=<something>&author=&i1l=<something>
The form sends its POST to /addData, which means you need to do so as well. If you're trying to POST to the page which's code you've shown above it won't work.
The URL starts with a slash (/), meaning addData is located in the website's root directory. Thus you should send your POST to: http://www.website.com/addData (or https:// depending on what the website is using).

anchor is not redirecting to display inside ng-view, rather reloading with new page

I wrote a simple angular application in a learning purpose. However the controllers are working in my system but not in plunker. But, that is not my concern. My concern is I am unable to see the linked pages inside ng-view. They are rather opening as a new page replacing the home page. Secondly, the expressions are not reflecting their values. Kindly help me out. I have uploaded the codes in plunker.
Link to Plunker
<div ng-controller="RamFirstCtrl">{{name}}</div>
<div ng-include="'navbar-top.html'"></div>
<div style="border:1px solid green; position:relative;" ng-view></div>
Noticed couple thing:
http to https, there is error in console, it might be the reason it doesn't work in plunker
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
you have to use the url define in your router:
ng-href="aboutUS.html" to ng-href="#!/aboutUS"
.when("/aboutUS", {
templateUrl : "aboutUS.html"
})
<div>
<a ng-href="#!/aboutUS">
AboutUs
</a>
</div>
Note:#! will be added to url by angular router by default

Why does Status.CLIENT_ERROR_UNAUTHORIZED in Restlet returns an EmptyRepresentation when post

The Post method in Restlet 2.x returns an EmptyRepresentation when Status.CLIENT_ERROR_UNAUTHORIZED, it does not do so in Get-method.
Why is that?
I can't reproduce your problem. Could you give the code you use so I can make a try? I guess that you use the method setStatus but you shoud throw a ResourceException with this status code.
When using this code:
public class TestServerResource extends ServerResource {
#Post
public Representation test(Representation repr) {
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED);
}
}
I have the following response:
405 Method Not Allowed
<html>
<head>
<title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Method Not Allowed</p>
<p>The method specified in the request is not allowed for the resource identified by the request URI</p>
<p>You can get technical details here.<br>
Please continue your visit at our home page.
</p>
</body>
</html>
Hope it will help you.
Thierry

ReCAPTCHA doesn't work on localhost

I'm building a website with a form with reCAPTCHA check. As required from Google documentation, I've created a key for the target domain. Then, I've created a form containing reCAPTCHA section
HTML form
<form method="post" action="index.php">
<div class="g-recaptcha" data-sitekey="PUBLIC_KEY"></div>
<input type="submit" name="submit" />
</form>
PHP response check
When form is submitted, reCAPTCHA response is verified (in this example, it's simply printed).
$recaptcha = filter_input(INPUT_POST, 'g-recaptcha-response', FILTER_SANITIZE_STRING);
$googleurl = "https://www.google.com/recaptcha/api/siteverify";
$privatekey = "PRIVATE_KEY";
$remoteip = $_SERVER['REMOTE_ADDR'];
$curl = new Curl($googleurl."?secret=".$privatekey."&response=".$recaptcha."&remoteip=".$remoteip);
$response = json_decode($curl->exec(), true);
print_r($response);
die();
Curl is a class that simply builds a curl request and return result.
The problem
The snippet works fine online and I've checked $response values both with success and error cases. But during development, I must use it on localhost too. As stated in this post, all keys should work locally. But when I run the code, nothing is shown.
Though this question is older I post the answer because many people may run into the same problem. I think that this may be related to the general authentification problem with running reCaptcha on localhost which can be solved using secure token
I posted the solution here for reference
UPDATE - the working code:
For secure token generation I'm using slushie's php implementation
The PHP part:
<?PHP
use ReCaptchaSecureToken\ReCaptchaToken as ReCaptchaToken;
require_once("libs/ReCaptchaToken.php");
//Generate recaptcha token
$config = [ 'site_key' => 'place-your-site-key-here',
'site_secret' => 'place-your-secret-key-here'
];
$recaptcha_token = new ReCaptchaToken($config);
$recaptcha_session_id = uniqid('recaptcha');
$recaptcha_secure_token = $recaptcha_token->secureToken($recaptcha_session_id);
?>
The HTML:
<html>
<head>
...
<script src='//www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form>
...
<div class="g-recaptcha" data-sitekey="place-your-site-key-here" data-stoken="<?PHP echo $recaptcha_secure_token; ?>"></div>
</form>
</body>
</html>

Newbie Dojo - Google CDN Question

I have a test jsp with:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js" type="text/javascript">
</script>
<script type="text/javascript">
dojo.require("dojo.widget.Tree");
dojo.require("dojo.widget.TreeSelector");
dojo.require("dojo.widget.TreeNode");
dojo.require("dojo.widget.TreeContextMenu");
</script>
</head>
<body>
<div dojoType="TreeSelector" widgetId="treeSelector"></div>
<div dojoType="Tree" widgetId="treeWidget" selector="treeSelector"toggler="wipe">
<div dojoType="TreeNode" widgetId="1" title="First node" isFolder="false"></div>
<div dojoType="TreeNode" widgetId="2" title="Second node">
<div dojoType="TreeNode" widgetId="2.1" title="Second node First Child"></div>
<div dojoType="TreeNode" widgetId="2.2" title="Second node Second Child"></div>
</div>
<div dojoType="TreeNode" widgetId="3" title="Third node" isFolder="false"></div>
</div>
This will not work in any browser.
I thought this would be easy, it seems the dojo library is not being downloaded/found?
Do I need to do anything else?
Also, my IDE, JDeveloper, reports that the attribute "dojoType" is not defined on element div.
I have to say, this example looks like it is taken from a very old version of dojo, but you're trying to run it against Dojo 1.5. That most likely won't work. dojo.widget hasn't existed since...0.4, 0.9 maybe.
You may be right in your comment to the previous answer in that no parseOnLoad: true was necessary in the original example, but I'd also assure you that that example was not running any version of Dojo anywhere near what you're running it with.
Based on what you're looking at there, you may want to start somewhere like here: http://www.dojotoolkit.org/reference-guide/dijit/Tree.html
I'm not sure what the default behavior is when it's not present, but you probably need to define a djConfig with parseOnLoad set to true (or call the parser directly). See the following links for more information:
http://docs.dojocampus.org/djConfig
http://dojocampus.org/content/2008/03/08/the-dojo-parser/
Follow the:
Google AJAX Libraries API Dev Guide,
and the Google API Loader's Guide.
You need to:
register for an API key (or use a direct link as you did),
if not using a direct link but google.load, you need to defer the execution of your code using an onload callback.
Personally, I would just do something like:
within the <head> section of my.html:
<script type="text/javascript" src="http://www.google.com/jsapi?key=MY_API_KEY_GOES_HERE"></script>
<script type="text/javascript" src="my.js"></script>
in my.js:
google.load("dojo", "1.5", {
uncompressed: true
});
function OnLoad() {
/* do stuff here */
}
google.setOnLoadCallback(OnLoad);