小编noo*_*ker的帖子

无法使用ip:port访问WEB API,但在VS调试模式下可以使用localhost:port

我正在尝试从.net编写一个WEB API,并尝试让我的Android应用程序从sql server数据库中查询一些数据.

我编写了web api,它在调试模式下运行良好.

我的问题是我注意到该应用程序的URL是localhost:port,它运行正常.但是,当我尝试将其更改为MYIP:port (eg. http:192.168.X.1234)或者MYHOSTNAME:port (eg win7home:1234)这给了我Bad Request - Invalid Hostname.

我知道我可以将其部署到IIS并且我的IIS已经设置但我只是想知道它怎么会在调试模式下不起作用???

有没有办法让我在调试模式下运行它并同时在我的Android上测试,而不是每次我想要进行更改时都要部署它?

c# asp.net debugging android localhost

36
推荐指数
4
解决办法
6万
查看次数

在Python中使用装饰器进行类型检查

这更像是一个语法错误问题,我正在尝试在Python修饰器上做这个教程

http://www.learnpython.org/page/Decorators

我的尝试代码

def Type_Check(correct_type):
    def new_function(old_function):
        def another_newfunction(arg):
            if(isintance(arg, correct_type)):
                return old_function(arg)
            else:
                print "Bad Type"

    #put code here

@Type_Check(int)
def Times2(num):
    return num*2

print Times2(2)
Times2('Not A Number')

@Type_Check(str)
def First_Letter(word):
    return word[0]

print First_Letter('Hello World')
First_Letter(['Not', 'A', 'String'])
Run Code Online (Sandbox Code Playgroud)

我想知道什么是错的,请帮忙

python function decorator

2
推荐指数
1
解决办法
945
查看次数

C#HttpWebRequest Post Method表格中有很多参数

我正在编写一个简单的C#程序来做一些Web请求和发布数据.我理解基础知识如何工作如何使用密码和html表单的东西登录.但是我想知道是否有很多输入参数(例如这个问题页面),比如复选框和文本字段,是否有任何有效的方法比在字符串中硬编码20个参数并传入它?我可以读取html文件解析它并扫描输入并使用String builder来制作这样的字符串,但我想知道是否有比这更有效的方法呢?

    private HtmlAgilityPack.HtmlDocument getpage(string url ,String input)
    {
        try
        {
            Stream datastream;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.CookieContainer = new CookieContainer();
            request.CookieContainer.Add(cookies);
            request.AllowAutoRedirect = true;
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
            request.ContentType = "application/x-www-form-urlencoded";

            if (input!=null)
            {
                String postData = "";
                request.Method = "POST";
                if (input == "login")
                {
                    postData = String.Format("username={0}&password={1}", "myusername", "mypassword");
                }
                else if (input == "sendMessage")
                {
                //THIS IS THE LONG STRING THAT I DON'T WANT TO HARD CODE
                    postData …
Run Code Online (Sandbox Code Playgroud)

.net html c# parameters httpwebrequest

2
推荐指数
1
解决办法
2万
查看次数