我可以在调试模式下停止Visual Studio URL解码命令参数吗?

时间:2019-07-01 14:50:26

标签: visual-studio-2017 visual-studio-debugging win32-process

如果我将程序设置为回显命令参数,并在Visual Studio调试器中使用命令参数“ https%3a%2f%2fas”运行,它将回显'https://as'

但是,如果我从命令行'myprog.exe https%3a%2f%2fas'运行,它将回显'https%3a%2f%2fas'

为什么它对此处理方式有所不同,我该如何停止呢?我必须传递一个经过URL编码的参数,并且它不需要先由Visual Studio解释。

程序是C ++,如果有帮助,它是Visual Studio 2017。

1 个答案:

答案 0 :(得分:0)

  

我可以在调试模式下停止Visual Studio URL解码命令参数吗?

对不起,但我担心答案是否定的。测试后确实存在此问题,据我所知,VS中没有选项可以关闭或控制此行为。为此,我建议您可以Go Help=>Send Feedback=>Report a problem in VSreport this issue加入产品团队。

  

我必须传递一个经过URL编码的参数,并且不需要   首先由Visual Studio解释。

由于它在命令行中运行良好。因此,您需要在开发中的VS debug process期间获取UrlEncode格式字符串。为此,您可以尝试:

1 。在需要真正参数的位置之前添加一些代码,以对argv[1](我认为它是https://as)进行UrlEncode。有关如何进行UrlEncode的信息,请参见this issue

2 。以这种方式设置参数,在项目属性中将https% 3a% 2f% 2fas设置为argv[1]而不是https%3a%2f%2fas,然后添加代码以判断是否包含空格,if true =>编写代码以删除其中的空格并获取所需的新字符串(https%3a%2f%2fas

3 。配置自定义参数文件:

1#在vs中,右键单击项目=>将Text.txt文件添加到项目中。

2#将唯一的参数设置为Text.txt

enter image description here

然后,Text.txt的内容是自定义参数的集合。 例如:

在Text.txt文件的第1行是https%3a%2f%2fas,第2行是test,第3行是...

enter image description here

3#然后,您可以使用如下代码:

#include "pch.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
    ifstream infile(argv[1]); //open the file

    string MyArgus[10]; //create my alternative argus
    MyArgus[0] = argv[0]; //let the first argu of Myargus=original vs argu[0]
    if (infile.is_open() && infile.good()) {
        cout << "File is open."<<endl;
        string line = "";

        int num = 1;
        while (getline(infile, line)) {
            MyArgus[num] = line;
            num++;
        }
    }
    else {
        cout << "Failed to open file..";
    }

    cout << MyArgus[0]<<endl; // projectName.exe always
    cout << MyArgus[1]<<endl; // https%3a%2f%2fas
    cout << MyArgus[2]<<endl; // test
    return 0;
}

因此,您可以通过这种方式在Text.txt文件中编写参数来设置自定义参数,从而避免在VS中使用自动UrlDecode。

希望有帮助:)