upload values with webclient - vb.net

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).

Related

How can i use a template in the email body for Microsoft graph API?

I am looking to use the source code of an email which has the desired template that i need in the Microsoft Graph API.
The standard format for this looks like so:
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "HTML",
"content": "The new cafeteria is open."
},
The sourcecodes template that i am looking to use already has contentType etc within the code.I have tried removing contentType and content and just having the source code within the body but this still does not work. Below is start of the source code that i am looking to use:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if !mso]>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="http://www.opusenergy.com/wp-content/uploads/2016/03/Favicon-150x150.png" />
<title>Opus</title>
<!--[if (gte mso 9)|(IE)]>
<style type="text/css">
table {border-collapse: collapse !important;}
</style>
Any help will be greatly appreciated, Thank you.
The above payload is not what Graph API looks for. You need to specify the payload for the create message API call and the structure is given in the Graph API document. Still if you want to customize, you can do it, by making sure to modify/customize in-lines with Microsoft Graph API recommendation. Say i will put the HTML content inside the content of the Graph API call, specify the contenttype as HTML. This is the way i would start testing it make sure whether it's working or still i need to modify so that the message can show correctly in Outlook or not.
You tried the above recommendation and confirmed that it works.
If i want to send out email/template then i would first make sure it works in Word/Outlook; so that you can validate the HTML/CSS tags are working in, as i know that not all tags are not supported. Please keep this best practice and plan it accordingly. It will help you to build the template as you wish and you're guaranteed that the Outlook will show-up them as well.

Peerjs is not retrieved in vue js

I am trying to use peerjs in vue app. So I added the cdn script in vue index.html file's header like this.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta data-n-head="true" name="viewport" content="width=device-width, initial-scale=1.0">
<title>peer</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.9/peer.min.js"></script>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
Now in a components' mounted hook, I am doing this to just console the id
var peer1 = new Peer();
peer1.on('open', function(id) {
console.log('My peer1 ID is: ' + id);
});
Nothing happens.
I then created a simple html file and run that html file I was able to see the id.
Next I tired to see XHR tab, I see when running a plain html file, two ajax calls is sent and in the result an ID is returned. But in vue, there is nothing like this. All I get a socket that returns this values
{websocket: true, origins: ["*:*"], cookie_needed: false, entropy: 1058218289}
cookie_needed
:
false
entropy
:
1058218289
origins
:
[":"]
websocket
:
true
One more thing, peers js documentations says to use api key, but if I use api key nothing happens in vue or html. Without the key, in html file I get the id.
Anyone knows please help me. Thank you.

First test passes while second test (with same data) fail Selenium with Codeception

I'm a noob trying to learn Codeception with the Selenium WebServer and have come across a problem I can't seem to find an answer to. I'm writing a super basic test that ensure the data passed in a from in index.php, is the same on another page, toupper.php.
This is my index.php:
<?php $something = "Can you see me?"; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Convert Me!</title>
</head>
<body>
<h1>Convert Me!</h1>
<p>
<?php echo $something; ?>
</p>
<form action="toupper.php" method="post" id="post_form">
<label for="string">Convert to Uppercase:</label>
<input type="text" name="my_string" id="string">
<input id="submit" type="submit" name="submitButton" value="Convert">
</form>
</body>
</html>
This is my toupper.php:
<?php
$message = (!empty($_POST['my_string'])) ? strtoupper($_POST['my_string']) : "No string entered";
?>
<!DOCTYPE html>
<html>
<head>
<title>To Upper!</title>
</head>
<body>
<h1>To Upper!</h1>
<p class="message"><?php echo $message; ?></p>
<p>Back to form.</p>
</body>
</html>
I've created a simple testsuite:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure Toupper form works');
$I->amOnPage('index.php');
$I->see('Can you see me?');
$I->fillField('my_string', 'convert me to uppercase');
$I->click('Convert');
$I->amOnSubdomain('toupper.php');
$I->see('CONVERT ME TO UPPERCASE');
Now, whenever I run the test, the test passes, but when I run the exact test again with the same data, it fails. And I'm not using a database.
This is the error I get:
Scenario --
I am on page "index.php"
I see "Can you see me?"
I fill field "my_string","convert me to uppercase"
I click "Convert"
I am on subdomain "toupper.php"
I see "CONVERT ME TO UPPERCASE"
FAIL
--------------------------------------------------------------
Time: 2.59 seconds, Memory: 8.00MB
There was 1 failure:
---------
1) ToupperCept: Ensure toupper form works
Test tests/acceptance/ToupperCept.php
Step See "CONVERT ME TO UPPERCASE"
Fail Failed asserting that /toupper.php
-->
--> contains "convert me to uppercase".
Scenario Steps:
6. $I->see("CONVERT ME TO UPPERCASE")
5. $I->amOnSubdomain("toupper.php")
4. $I->click("Convert")
3. $I->fillField("my_string","convert me to uppercase")
2. $I->see("Can you see me?")
1. $I->amOnPage("index.php")
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
Can someone point me in the right direction as to how to solve this? I appreciate it!
UPDATE
Upon messing around with the test, that when I write an assertion looking for the text in uppercase on toupper.php, EX) $I->see('SOMETHING'); , the test fails. It seems that if the test fails at some point, all other assertions fail. Even when I comment out the failed assertion, all previous assertion fail upon running the test again. So confused!!
UPDATE2
Sorry for the multiple updates, but messing around a bit more, I switched browsers for webdriver from firefox to chrome. All my tests are passing flawlessly everytime. Strange that only having issues with firefox.
Try inserting a $I->pauseExecution(); in your test code just before the failing line. Then you can easily see what is happening in the browser window just before the fail. Possibly you are having an issue with Firefox retaining data in the form.

"You broke Reddit" when submitting new story

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.

Closing forms after successful submission Rails 3

I have a form in my rails 3 app that is used to create new tags. This page is opened in a new window and I would like for that window to close after a successful submission of a new tag. How should I go about doing that.
I tried <%= f.submit "Create Tag", :onclick => "window.close()" %> and that didn't work - it still followed through with the redirection.
How might I redirect to a javascript file that would close the window?
Here I tried to redirect to another html page, but it still doesn't close when I use rails, even though it works when I just load it manually.
> <!DOCTYPE html> <html> <head>
> <meta http-equiv="Content-type" content="text/html; charset=utf-8">
> </head>
>
> <body id="sample"
> onload="window.close()">
> This page was meant to close itself immediately using javascript.
> If it has not, please close it
> manually. </body> </html>
You can use render :text => '<script type="text/javascript"> window.close() </script> in your controller to close the window afterwards.
An alternative solution could be render :action => "window_closer" with windows_closer.html.erb being a HTML file with the same code (and maybe a body and a "Please close window now" text).
I used the best answer on this forum and it seems to work ... I'm not quite sure why.
http://www.google.com/support/forum/p/Chrome/thread?tid=23c03746e3aa03f9&hl=en
window.open('', '_self', '');
window.close();