spilt string with 2 or more possibilites with action script 2 - actionscript-2

I am trying to simplify a baseURL string with action script 2.
But I am having trouble as my base URL could have to possible begginings.
What I have so far.. Thanks to #Will Kru
.split("http://").join("").split("/")[0];
So if my baseURL is this... http://www.actionscript.com/category/splitting
Then the above code would return... www.actionscript.com
My next problem is, the baseURL could be in SSL mode. So the beggining of the string would be https://
So my question is - is there anyway to split the baseURL from the first :// and remove what ever appears before the :// - wether it is http or https
Many Thanks

You can use this.
.split("://")[1].split("/")[0]

Related

Why karate dsl replace "space" for "+" in param

i have this code:
Scenario: Get Token
Given url 'https://localhost/api/accessToken'
And param scope = 'collections payments'
Log:
1 > POST https://localhost/api/accessToken?scope=collections+payments
This Post faild for me.
Please, i need this:
https://localhost/api/accessToken?scope=collections%20payments
Karate is doing the right thing and your server probably has a bug.
Refer: https://stackoverflow.com/a/1634293/143475
But if you want to send it the way you are asking, put it as the URL itself, and don't use param:
* url 'https://httpbin.org/anything?foo=one%20two'
* method get
Explained here: https://stackoverflow.com/a/59977660/143475

OAuth 2(Pinterest) - Query Param in callback URL?

My OAuth 2 callback URL is:
https://www.my-site.com?fixed=value
Where I have a query param that's fixed and does not change(and it unfortunately needs to be there for unrelated reasons). When Pinterest does the redirect call after user logs in, they add the ? again. So something like:
https://www.my-site.com?fixed=value?code=122343
Where my API is interpreting the value of the fixed param as value?code=122343 and breaks down. Is there any around this ?
You have to change callback url from https://www.my-site.com?fixed=value to https://www.my-site.com/fixed/value or you can try to add a custom parser to parse this url in your API.
In my case I was having a query param option called 'state'.I put my constant data in it and after authorize, I got my constant data in 'state' query param again when I redirected to my app.

Change redirected URL in Scrapy

It is possible to change a redirected url in scrapy?
For example, I crawl an url:
http://someurl.com/A
which has a redirect to
http://redirectedurl.com:8080/A
This url fails because of the port number. The good URL needs to be without a port number, so I would like to change it to
http://redirectedurl.com/A
I tried to update the request.meta with redirect_urls having the new url without a port.
The docs says that MetaRefreshMiddleware obeys the redirect_urls, but no succes
meta.update({'redirect_urls': ['http://redirectedurl.com/A '] })
r = Request(url=url, callback=callback, meta=meta)
Any ideas?
No need to go deep and try to fix things "under the hood". You can just check if the request was redirected, and then create a new request with the modified URL:
import re
if 'redirect_urls' in response.meta:
new_url = re.sub(":\d+","", response.url)
yield Request(new_url)
Of course, you would add additional checks there, this is just a minimum example.

jmeter help - test around polling /w meta refresh

I am new to jmeter and am working on putting together a test plan. The hurdle I've encountered is as follows:
First, a POST is made to processForm.aspx
Then, the user is redirected to pleaseWait.aspx
This page either redirects immediately to results.aspx OR loads, with a META REFRESH tag set to refresh in 5 seconds (and this step is repeated).
Now -- I can get this to execute by doing the following:
HTTP Sampler POST to processForm.aspx
Assert Response contains "<something on pleaseWait.aspx>"
While LAST
HTTP Sampler GET to pleaseWait.aspx
Assert Response contains "<something on results.aspx>"
However -- I don't care for this method, because it results in failed assertions (even though things are working as expected). I am sure there must be some other way to do this? Anyone more familiar with JMeter than I?
UPDATE:
Got it going by using Regular Expression Extractor instead of Assertions.
1) Add a User Defined Variables section at Test Plan Root
2) Add a variable to it "LoginWait" and "false"
HTTP Sampler POST to processForm.aspx
RegEx Extract Response Body contains "<something on pleaseWait.aspx>" into LoginWait
While ${LoginWait}
HTTP Sampler GET to pleaseWait.aspx
RegEx Extract Response Body contains "<something on pleaseWait.aspx>" into LoginWait
...
You could try using "follow redirects" on your HTTP Request. It would eliminate the logic you need, and still get you to the page you're going.

how to set HTTP_HOST for WebTestCases in Symfony2

My application is generating some absolute links via $this->get('request')->getHost().
Problem is: when I try to run testcases, I get following error message:
[exception] 500 | Internal Server Error | Twig_Error_Runtime
[message] An exception has been thrown during the rendering of a template ("Undefined index: HTTP_HOST") in "::base.html.twig" at line 69.
Somehow it's clear to me that there is no host when calling my app via CLI, but I think there must be a way to prevent Symfony2 from throwing that error.
Anyone knows how to get rid of it?
You could create the request like this:
$request = Request::create('http://example.com/path');
That will make the HTTP host be set.
Maybe what you could do is to inject the host you need directly in the request headers before calling the getter. The host is retrieved by looking at various parameter values. First, the headers parameter X_FORWARDED_HOST is checked to see if it is set. If it is set, it is returned otherwise the method getHost checks if the headers parameter HOST is set then the if the server parameter SERVER_NAME is set and finally if the server parameter SERVER_ADDR is set.
What you could try is to set the header parameter HOST like this before calling the getHost method:
$request = $this->get('request');
$request->headers->set('HOST', 'yourhosthere');
$request->getHost(); // Should return yourhosthere
That being said, I'm not sure this will solve the problem because the error you mentioning tells us that the template tries to retrieve the value of the index HTTP_HOST but it is not defined. Looking at the methods $request->getHost and $request->getHttpHost, I don't see anything trying to retrieve a value having HTTP_HOST as the index but I could have missed it. Could you post the file ::base.html.twig to see if the problem could be lying there.
Regards,
Matt
Thanks guys- your answers lead me into the right direction.
This is no Symfony2 issue, as i figured out:
It's just the facebook API PHP wrapper which directly accesses the SERVER parameters. This code solved my issue:
$facebook = $this->container->get('facebook');
$returnUrl = 'http://'.$request->getHost();
$returnUrl .= $this->container->get('router')->generate('_validate_facebook');
$_SERVER['HTTP_HOST'] = $request->getHost();
$_SERVER['REQUEST_URI'] = $request->getRequestUri();
$loginUrl = $facebook->getLoginUrl(array(
'req_perms' => 'publish_stream',
'next' => $returnUrl,
));
return $loginUrl;
now my app runs from web and CLI again